diff --git a/src/Composer/Artifact/ComposerFile.php b/src/Composer/Artifact/ComposerFile.php index b796e1b20..4da5194f4 100644 --- a/src/Composer/Artifact/ComposerFile.php +++ b/src/Composer/Artifact/ComposerFile.php @@ -16,35 +16,21 @@ use Webmozart\Assert\Assert; -final class ComposerFile +final readonly class ComposerFile { - private readonly ?string $path; - private readonly array $contents; - public static function createEmpty(): self { return new self(null, []); } - public function __construct(?string $path, array $contents) - { + public function __construct( + public ?string $path, + public array $decodedContents, + ) { Assert::nullOrNotEmpty($path); if (null === $path) { - Assert::same([], $contents); + Assert::same([], $decodedContents); } - - $this->path = $path; - $this->contents = $contents; - } - - public function getPath(): ?string - { - return $this->path; - } - - public function getDecodedContents(): array - { - return $this->contents; } } diff --git a/src/Composer/Artifact/ComposerFiles.php b/src/Composer/Artifact/ComposerFiles.php index c6742619f..6ab9f62b0 100644 --- a/src/Composer/Artifact/ComposerFiles.php +++ b/src/Composer/Artifact/ComposerFiles.php @@ -59,7 +59,7 @@ public function getPaths(): array return array_values( array_filter( array_map( - static fn (ComposerFile $file): ?string => $file->getPath(), + static fn (ComposerFile $file): ?string => $file->path, [$this->composerJson, $this->composerLock, $this->installedJson], ), ), diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index f50d8f9d2..9863fa9e9 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -226,7 +226,7 @@ public static function create(?string $file, stdClass $raw): self $excludeComposerFiles = self::retrieveExcludeComposerFiles($raw, $logger); - $mainScriptPath = self::retrieveMainScriptPath($raw, $basePath, $composerFiles->getComposerJson()->getDecodedContents(), $logger); + $mainScriptPath = self::retrieveMainScriptPath($raw, $basePath, $composerFiles->getComposerJson()->decodedContents, $logger); $mainScriptContents = self::retrieveMainScriptContents($mainScriptPath); [$tmpOutputPath, $outputPath] = self::retrieveOutputPath($raw, $basePath, $mainScriptPath, $logger); @@ -255,8 +255,8 @@ public static function create(?string $file, stdClass $raw): self $checkRequirements = self::retrieveCheckRequirements( $raw, - null !== $composerFiles->getComposerJson()->getPath(), - null !== $composerFiles->getComposerLock()->getPath(), + null !== $composerFiles->getComposerJson()->path, + null !== $composerFiles->getComposerLock()->path, false === $isStubGenerated && null === $stubPath, $logger, ); @@ -265,8 +265,8 @@ public static function create(?string $file, stdClass $raw): self $devPackages = ComposerConfiguration::retrieveDevPackages( $basePath, - new DecodedComposerJson($composerFiles->getComposerJson()->getDecodedContents()), - new DecodedComposerLock($composerFiles->getComposerLock()->getDecodedContents()), + new DecodedComposerJson($composerFiles->getComposerJson()->decodedContents), + new DecodedComposerLock($composerFiles->getComposerLock()->decodedContents), $excludeDevPackages, ); @@ -497,22 +497,22 @@ public function getBasePath(): string public function getComposerJson(): ?string { - return $this->composerJson->getPath(); + return $this->composerJson->path; } public function getDecodedComposerJsonContents(): ?array { - return null === $this->composerJson->getPath() ? null : $this->composerJson->getDecodedContents(); + return null === $this->composerJson->path ? null : $this->composerJson->decodedContents; } public function getComposerLock(): ?string { - return $this->composerLock->getPath(); + return $this->composerLock->path; } public function getDecodedComposerLockContents(): ?array { - return null === $this->composerLock->getPath() ? null : $this->composerLock->getDecodedContents(); + return null === $this->composerLock->path ? null : $this->composerLock->decodedContents; } /** @@ -858,7 +858,7 @@ private static function collectFiles( if ($autodiscoverFiles || $forceFilesAutodiscovery) { [$filesToAppend, $directories] = self::retrieveAllDirectoriesToInclude( $basePath, - $composerFiles->getComposerJson()->getDecodedContents(), + $composerFiles->getComposerJson()->decodedContents, $devPackages, $composerFiles->getPaths(), $excludedPaths, @@ -962,8 +962,8 @@ private static function retrieveFiles( $excludedFiles = array_flip($excludedFiles); $files = array_filter([ - $composerFiles->getComposerJson()->getPath(), - $composerFiles->getComposerLock()->getPath(), + $composerFiles->getComposerJson()->path, + $composerFiles->getComposerLock()->path, ]); if (false === isset($raw->{$key})) { @@ -1551,22 +1551,22 @@ private static function retrieveDumpAutoload(stdClass $raw, ComposerFiles $compo self::checkIfDefaultValue($logger, $raw, self::DUMP_AUTOLOAD_KEY, null); $canDumpAutoload = ( - null !== $composerFiles->getComposerJson()->getPath() + null !== $composerFiles->getComposerJson()->path && ( // The composer.lock and installed.json are optional (e.g. if there is no dependencies installed) // but when one is present, the other must be as well otherwise the dumped autoloader will be broken ( - null === $composerFiles->getComposerLock()->getPath() - && null === $composerFiles->getInstalledJson()->getPath() + null === $composerFiles->getComposerLock()->path + && null === $composerFiles->getInstalledJson()->path ) || ( - null !== $composerFiles->getComposerLock()->getPath() - && null !== $composerFiles->getInstalledJson()->getPath() + null !== $composerFiles->getComposerLock()->path + && null !== $composerFiles->getInstalledJson()->path ) || ( - null === $composerFiles->getComposerLock()->getPath() - && null !== $composerFiles->getInstalledJson()->getPath() - && [] === $composerFiles->getInstalledJson()->getDecodedContents() + null === $composerFiles->getComposerLock()->path + && null !== $composerFiles->getInstalledJson()->path + && [] === $composerFiles->getInstalledJson()->decodedContents ) ) ); diff --git a/tests/Composer/Artifact/ComposerFileTest.php b/tests/Composer/Artifact/ComposerFileTest.php index 4039b4863..73fbb823a 100644 --- a/tests/Composer/Artifact/ComposerFileTest.php +++ b/tests/Composer/Artifact/ComposerFileTest.php @@ -34,8 +34,8 @@ public function test_it_can_be_created(Closure $create, ?string $expectedPath, a self::assertInstanceOf(ComposerFile::class, $actual); - self::assertSame($expectedPath, $actual->getPath()); - self::assertSame($expectedContents, $actual->getDecodedContents()); + self::assertSame($expectedPath, $actual->path); + self::assertSame($expectedContents, $actual->decodedContents); } #[DataProvider('invalidInstantiatorsProvider')] diff --git a/tests/Configuration/ConfigurationTest.php b/tests/Configuration/ConfigurationTest.php index ceb6b82d6..45069ceaa 100644 --- a/tests/Configuration/ConfigurationTest.php +++ b/tests/Configuration/ConfigurationTest.php @@ -3042,8 +3042,8 @@ public function test_it_can_be_exported(): void -alias: "test.phar" -basePath: "/path/to" -composerJson: KevinGH\Box\Composer\Artifact\ComposerFile {#100 - -path: "composer.json" - -contents: array:1 [ + +path: "composer.json" + +decodedContents: array:1 [ "config" => array:3 [ "bin-dir" => "bin" "platform" => array:1 [ @@ -3054,8 +3054,8 @@ public function test_it_can_be_exported(): void ] } -composerLock: KevinGH\Box\Composer\Artifact\ComposerFile {#100 - -path: "composer.lock" - -contents: [] + +path: "composer.lock" + +decodedContents: [] } -files: array:6 [ 0 => "bar.php" diff --git a/tests/Console/Command/CompileTest.php b/tests/Console/Command/CompileTest.php index b3ebac582..8b37a4028 100644 --- a/tests/Console/Command/CompileTest.php +++ b/tests/Console/Command/CompileTest.php @@ -1188,12 +1188,12 @@ public function test_it_can_build_a_phar_file_in_debug_mode(): void -alias: "index.phar" -basePath: "/path/to" -composerJson: KevinGH\Box\Composer\Artifact\ComposerFile {#140 - -path: null - -contents: [] + +path: null + +decodedContents: [] } -composerLock: KevinGH\Box\Composer\Artifact\ComposerFile {#140 - -path: null - -contents: [] + +path: null + +decodedContents: [] } -files: [] -binaryFiles: []