Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
],
"require": {
"php": "8.1.*||8.2.*||8.3.*||8.4.*||8.5.*",
"composer/composer": "^2.8.12",
"composer/composer": "^2.9.1",
"composer/pcre": "^3.3.2",
"composer/semver": "^3.4.4",
"fidry/cpu-core-counter": "^1.3.0",
Expand All @@ -37,15 +37,16 @@
"symfony/console": "^6.4.27",
"symfony/event-dispatcher": "^6.4.25",
"symfony/process": "^6.4.26",
"thephpf/attestation": "^0.0.2",
"thephpf/attestation": "^0.0.3",
"webmozart/assert": "^1.12.1"
},
"require-dev": {
"ext-openssl": "*",
"behat/behat": "^3.26.0",
"bnf/phpstan-psr-container": "^1.1",
"doctrine/coding-standard": "^14.0.0",
"phpstan/phpstan": "^2.1.31",
"phpstan/phpstan": "^2.1.32",
"phpstan/phpstan-webmozart-assert": "^2.0",
"phpunit/phpunit": "^10.5.58"
},
"replace": {
Expand Down
218 changes: 140 additions & 78 deletions composer.lock

Large diffs are not rendered by default.

24 changes: 0 additions & 24 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,6 @@ parameters:
count: 1
path: src/Command/RepositoryAddCommand.php

-
message: '#^Parameter \#1 \$type of method Php\\Pie\\ComposerIntegration\\PieJsonEditor\:\:addRepository\(\) expects ''composer''\|''path''\|''vcs'', string given\.$#'
identifier: argument.type
count: 1
path: src/Command/RepositoryAddCommand.php

-
message: '#^Cannot cast mixed to string\.$#'
identifier: cast.string
Expand Down Expand Up @@ -414,18 +408,6 @@ parameters:
count: 2
path: test/unit/ComposerIntegration/BundledPhpExtensionsRepositoryTest.php

-
message: '#^Method Php\\PieUnitTest\\ComposerIntegration\\PieJsonEditorTest\:\:normaliseJson\(\) should return string but returns string\|false\.$#'
identifier: return.type
count: 1
path: test/unit/ComposerIntegration/PieJsonEditorTest.php

-
message: '#^Parameter \#1 \$fileContent of method Php\\PieUnitTest\\ComposerIntegration\\PieJsonEditorTest\:\:normaliseJson\(\) expects string, string\|false given\.$#'
identifier: argument.type
count: 9
path: test/unit/ComposerIntegration/PieJsonEditorTest.php

-
message: '#^Match expression does not handle remaining value\: string$#'
identifier: match.unhandled
Expand Down Expand Up @@ -516,12 +498,6 @@ parameters:
count: 1
path: test/unit/Platform/TargetPhp/PhpBinaryPathTest.php

-
message: '#^Parameter \#4 \$body of class Composer\\Util\\Http\\Response constructor expects string\|null, string\|false given\.$#'
identifier: argument.type
count: 1
path: test/unit/SelfManage/Update/FetchPieReleaseFromGitHubTest.php

-
message: '#^Method Php\\PieUnitTest\\SelfManage\\Verify\\FallbackVerificationUsingOpenSslTest\:\:prepareCertificateAndSignature\(\) should return array\{string, string\} but returns array\{mixed, mixed\}\.$#'
identifier: return.type
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
includes:
- phpstan-baseline.neon
- vendor/bnf/phpstan-psr-container/extension.neon
- vendor/phpstan/phpstan-webmozart-assert/extension.neon

parameters:
level: 10
Expand Down
4 changes: 1 addition & 3 deletions src/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use Composer\IO\IOInterface;
use Composer\IO\NullIO;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\ComposerIntegration\PieComposerFactory;
use Php\Pie\ComposerIntegration\PieComposerRequest;
Expand Down Expand Up @@ -118,8 +117,7 @@ public function execute(InputInterface $input, OutputInterface $output): int
);

$httpDownloader = new HttpDownloader($this->quieterConsoleIo, $composer->getConfig());
$authHelper = new AuthHelper($this->quieterConsoleIo, $composer->getConfig());
$fetchLatestPieRelease = new FetchPieReleaseFromGitHub($this->githubApiBaseUrl, $httpDownloader, $authHelper);
$fetchLatestPieRelease = new FetchPieReleaseFromGitHub($this->githubApiBaseUrl, $httpDownloader);
$verifyPiePhar = VerifyPieReleaseUsingAttestation::factory();

if ($updateChannel === Channel::Nightly) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Composer\Installer\InstallerEvents;
use Composer\IO\IOInterface;
use Composer\Package\CompletePackageInterface;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\ComposerIntegration\PieComposerRequest;
use Php\Pie\DependencyResolver\Package;
Expand Down Expand Up @@ -90,7 +89,6 @@ function (OperationInterface $operation): void {
$url = $packageReleaseAssets->findMatchingReleaseAssetUrl(
$targetPlatform,
$piePackage,
new AuthHelper($this->io, $this->composer->getConfig()),
new HttpDownloader($this->io, $this->composer->getConfig()),
$possibleAssetNames,
);
Expand Down
7 changes: 2 additions & 5 deletions src/Downloading/GithubPackageReleaseAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Php\Pie\Downloading;

use Composer\Downloader\TransportException;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\DependencyResolver\Package;
use Php\Pie\Platform\TargetPlatform;
Expand All @@ -31,14 +30,13 @@ public function __construct(
public function findMatchingReleaseAssetUrl(
TargetPlatform $targetPlatform,
Package $package,
AuthHelper $authHelper,
HttpDownloader $httpDownloader,
array $possibleReleaseAssetNames,
): string {
$releaseAsset = $this->selectMatchingReleaseAsset(
$targetPlatform,
$package,
$this->getReleaseAssetsForPackage($package, $authHelper, $httpDownloader),
$this->getReleaseAssetsForPackage($package, $httpDownloader),
$possibleReleaseAssetNames,
);

Expand Down Expand Up @@ -72,7 +70,6 @@ private function selectMatchingReleaseAsset(
/** @return list<array{name: non-empty-string, browser_download_url: non-empty-string, ...}> */
private function getReleaseAssetsForPackage(
Package $package,
AuthHelper $authHelper,
HttpDownloader $httpDownloader,
): array {
Assert::notNull($package->downloadUrl());
Expand All @@ -84,7 +81,7 @@ private function getReleaseAssetsForPackage(
'retry-auth-failure' => true,
'http' => [
'method' => 'GET',
'header' => $authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $package->downloadUrl()),
'header' => [],
],
],
)->decodeJson();
Expand Down
2 changes: 0 additions & 2 deletions src/Downloading/PackageReleaseAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Php\Pie\Downloading;

use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\DependencyResolver\Package;
use Php\Pie\Platform\TargetPlatform;
Expand All @@ -20,7 +19,6 @@ interface PackageReleaseAssets
public function findMatchingReleaseAssetUrl(
TargetPlatform $targetPlatform,
Package $package,
AuthHelper $authHelper,
HttpDownloader $httpDownloader,
array $possibleReleaseAssetNames,
): string;
Expand Down
1 change: 0 additions & 1 deletion src/ExtensionName.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ public static function determineFromComposerPackage(PackageInterface $package):
) {
$packageNameParts = explode('/', $package->getPrettyName());
Assert::count($packageNameParts, 2, 'Expected a package name like vendor/package for ' . $package->getPrettyName());
Assert::keyExists($packageNameParts, 1);

return self::normaliseFromString($packageNameParts[1]);
}
Expand Down
6 changes: 2 additions & 4 deletions src/SelfManage/Update/FetchPieReleaseFromGitHub.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Php\Pie\SelfManage\Update;

use Composer\Package\Version\VersionParser;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\File\BinaryFile;
use RuntimeException;
Expand All @@ -28,7 +27,6 @@ final class FetchPieReleaseFromGitHub implements FetchPieRelease
public function __construct(
private readonly string $githubApiBaseUrl,
private readonly HttpDownloader $httpDownloader,
private readonly AuthHelper $authHelper,
) {
}

Expand All @@ -42,7 +40,7 @@ public function latestReleaseMetadata(Channel $updateChannel): ReleaseMetadata
'retry-auth-failure' => true,
'http' => [
'method' => 'GET',
'header' => $this->authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $url),
'header' => [],
],
],
)->decodeJson();
Expand Down Expand Up @@ -118,7 +116,7 @@ public function downloadContent(ReleaseMetadata $releaseMetadata): BinaryFile
'retry-auth-failure' => true,
'http' => [
'method' => 'GET',
'header' => $this->authHelper->addAuthenticationHeader([], $this->githubApiBaseUrl, $releaseMetadata->downloadUrl),
'header' => [],
],
],
)->getBody();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use Composer\Factory;
use Composer\IO\NullIO;
use Composer\Package\CompletePackage;
use Composer\Util\AuthHelper;
use Composer\Util\HttpDownloader;
use Php\Pie\DependencyResolver\Package;
use Php\Pie\Downloading\GithubPackageReleaseAssets;
Expand Down Expand Up @@ -65,7 +64,6 @@ public function testDeterminingReleaseAssetUrlForWindows(): void
->findMatchingReleaseAssetUrl(
$targetPlatform,
$package,
new AuthHelper($io, $config),
new HttpDownloader($io, $config),
WindowsExtensionAssetName::zipNames(
$targetPlatform,
Expand Down
78 changes: 63 additions & 15 deletions test/unit/ComposerIntegration/PieJsonEditorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use function dirname;
use function file_get_contents;
use function file_put_contents;
use function json_decode;
use function json_encode;
use function sys_get_temp_dir;
Expand All @@ -35,6 +36,53 @@ public function testCreatingPieJson(): void
);
}

public function testCanReadOldRepositoryConfiguration(): void
{
$testPieJson = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_json_test_', true) . '.json';

$editor = new PieJsonEditor($testPieJson, dirname($testPieJson));
$editor->ensureExists();
file_put_contents(
$testPieJson,
$this->normaliseJson(
<<<'JSON'
{
"repositories": {
"https://github.com/php/pie": {
"type": "vcs",
"url": "https://github.com/php/pie"
}
}
}
JSON,
),
);

$editor->addRepository('vcs', 'https://github.com/asgrim/example_pie_extension');

self::assertSame(
$this->normaliseJson(
<<<'JSON'
{
"repositories": [
{
"name": "https://github.com/php/pie",
"type": "vcs",
"url": "https://github.com/php/pie"
},
{
"name": "https://github.com/asgrim/example_pie_extension",
"type": "vcs",
"url": "https://github.com/asgrim/example_pie_extension"
}
]
}
JSON,
),
$this->normaliseJson(file_get_contents($testPieJson)),
);
}

public function testCanAddRequire(): void
{
$testPieJson = sys_get_temp_dir() . DIRECTORY_SEPARATOR . uniqid('pie_json_test_', true) . '.json';
Expand Down Expand Up @@ -94,12 +142,13 @@ public function testCanAddAndRemoveRepositories(): void

$expectedRepoContent = $this->normaliseJson(<<<'EOF'
{
"repositories": {
"https://github.com/php/pie": {
"repositories": [
{
"name": "https://github.com/php/pie",
"type": "vcs",
"url": "https://github.com/php/pie"
}
}
]
}
EOF);

Expand All @@ -116,8 +165,6 @@ public function testCanAddAndRemoveRepositories(): void

$noRepositoriesContent = $this->normaliseJson(<<<'EOF'
{
"repositories": {
}
}
EOF);

Expand All @@ -135,9 +182,11 @@ public function testCanAddAndRemoveRepositories(): void
self::assertSame(
$this->normaliseJson(<<<'EOF'
{
"repositories": {
"packagist.org": false
}
"repositories": [
{
"packagist.org": false
}
]
}
EOF),
$this->normaliseJson(file_get_contents($testPieJson)),
Expand All @@ -163,12 +212,13 @@ public function testCanAddAndRemoveWithTrailingSlash(): void

$expectedRepoContent = $this->normaliseJson(<<<'EOF'
{
"repositories": {
"/pwd/dummy": {
"repositories": [
{
"name": "/pwd/dummy",
"type": "path",
"url": "/pwd/dummy/"
}
}
]
}
EOF);

Expand All @@ -185,8 +235,6 @@ public function testCanAddAndRemoveWithTrailingSlash(): void

$noRepositoriesContent = $this->normaliseJson(<<<'EOF'
{
"repositories": {
}
}
EOF);

Expand All @@ -196,8 +244,8 @@ public function testCanAddAndRemoveWithTrailingSlash(): void
);
}

private function normaliseJson(string $fileContent): string
private function normaliseJson(string|false $fileContent): string
{
return json_encode(json_decode($fileContent));
return (string) json_encode(json_decode((string) $fileContent));
}
}
Loading