From 660a3f42d1527913360ccdc3bee3b51f901300a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 21 Nov 2023 22:25:47 +0100 Subject: [PATCH 01/12] setup rector --- Makefile | 24 +++++++++++++++++-- rector.php | 10 +++++++- src/Phar/PharMeta.php | 3 ++- src/functions.php | 6 +++-- .../DecodedComposerJsonTest.php | 2 +- .../DecodedComposerLockTest.php | 2 +- vendor-bin/rector/composer.json | 2 +- 7 files changed, 40 insertions(+), 9 deletions(-) diff --git a/Makefile b/Makefile index 18ffa3765..1fe7f0324 100644 --- a/Makefile +++ b/Makefile @@ -41,6 +41,9 @@ INFECTION_SRC := $(shell find src tests) phpunit.xml.dist PHP_CS_FIXER_BIN = vendor-bin/php-cs-fixer/vendor/bin/php-cs-fixer PHP_CS_FIXER = $(PHP_CS_FIXER_BIN) +RECTOR_BIN = vendor-bin/rector/vendor/bin/rector +RECTOR = $(RECTOR_BIN) + WEBSITE_SRC := mkdocs.yaml $(shell find doc) # This is defined in mkdocs.yaml#site_dir WEBSITE_OUTPUT = dist/website @@ -157,7 +160,7 @@ cs: ## Fixes CS cs: root_cs requirement_checker_cs .PHONY: root_cs -root_cs: gitignore_sort composer_normalize php_cs_fixer +root_cs: gitignore_sort composer_normalize rector php_cs_fixer .PHONY: requirement_checker_cs requirement_checker_cs: @@ -169,7 +172,7 @@ cs_lint: ## Lints CS cs_lint: root_cs_lint requirement_checker_cs_lint .PHONY: root_cs_lint -root_cs_lint: composer_normalize_lint php_cs_fixer_lint +root_cs_lint: composer_normalize_lint rector_lint php_cs_fixer_lint .PHONY: requirement_checker_cs_lint requirement_checker_cs_lint: @@ -183,6 +186,14 @@ php_cs_fixer: $(PHP_CS_FIXER_BIN) dist php_cs_fixer_lint: $(PHP_CS_FIXER_BIN) dist $(PHP_CS_FIXER) fix --ansi --verbose --dry-run --diff +.PHONY: rector +rector: $(RECTOR_BIN) + $(RECTOR) + +.PHONY: rector_lint +rector_lint: $(RECTOR_BIN) + $(RECTOR) --dry-run + .PHONY: composer_normalize composer_normalize: composer.json vendor composer normalize --ansi @@ -354,6 +365,15 @@ vendor-bin/php-cs-fixer/composer.lock: vendor-bin/php-cs-fixer/composer.json @echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)" @echo "$$ composer bin php-cs-fixer update --lock && touch -c $(@)" +$(RECTOR_BIN): vendor-bin/rector/vendor + touch -c $@ +vendor-bin/rector/vendor: vendor-bin/rector/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR) + composer bin rector install + touch -c $@ +vendor-bin/rector/composer.lock: vendor-bin/rector/composer.json + @echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)" + @echo "$$ composer bin rector update --lock && touch -c $(@)" + .PHONY: infection_install infection_install: $(INFECTION_BIN) diff --git a/rector.php b/rector.php index 9f19a2ac1..210dffafb 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,14 @@ $rectorConfig->importNames(); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, + LevelSetList::UP_TO_PHP_82, + ]); + + $rectorConfig->skip([ + \Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector::class, + \Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class => [ + __DIR__.'/src/Configuration/Configuration.php', + ], + \Rector\Php73\Rector\String_\SensitiveHereNowDocRector::class, ]); }; diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index af51a3a4b..3aea0927b 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -28,6 +28,7 @@ use function Safe\realpath; use function sprintf; use function var_export; +use const JSON_THROW_ON_ERROR; use const SORT_LOCALE_STRING; /** @@ -82,7 +83,7 @@ public static function fromPhar(Phar|PharData $phar, ?string $pubKeyContent): se public static function fromJson(string $json): self { - $decodedJson = json_decode($json, true); + $decodedJson = json_decode($json, true, flags: JSON_THROW_ON_ERROR); $filesMeta = $decodedJson['filesMeta']; diff --git a/src/functions.php b/src/functions.php index b8e616b7e..81e65f619 100644 --- a/src/functions.php +++ b/src/functions.php @@ -18,11 +18,13 @@ use Composer\InstalledVersions; use ErrorException; use Fidry\Console\IO; +use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder; use KevinGH\Box\Console\Php\PhpSettingsHandler; use Phar; use Symfony\Component\Console\Helper\Helper; use Symfony\Component\Console\Logger\ConsoleLogger; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Finder\Finder as SymfonyFinder; use Webmozart\Assert\Assert; use function bin2hex; use function class_alias; @@ -173,8 +175,8 @@ function format_time(float $secs): string function register_aliases(): void { // Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file. - if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) { - class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class); + if (false === class_exists(IsolatedFinder::class)) { + class_alias(SymfonyFinder::class, IsolatedFinder::class); } } diff --git a/tests/RequirementChecker/DecodedComposerJsonTest.php b/tests/RequirementChecker/DecodedComposerJsonTest.php index af63d04ed..375d2b092 100644 --- a/tests/RequirementChecker/DecodedComposerJsonTest.php +++ b/tests/RequirementChecker/DecodedComposerJsonTest.php @@ -15,7 +15,7 @@ namespace KevinGH\Box\RequirementChecker; use PHPUnit\Framework\TestCase; -use function json_decode; +use function Safe\json_decode; /** * @covers \KevinGH\Box\RequirementChecker\DecodedComposerJson diff --git a/tests/RequirementChecker/DecodedComposerLockTest.php b/tests/RequirementChecker/DecodedComposerLockTest.php index 1a8658d57..7a4b5f759 100644 --- a/tests/RequirementChecker/DecodedComposerLockTest.php +++ b/tests/RequirementChecker/DecodedComposerLockTest.php @@ -15,7 +15,7 @@ namespace KevinGH\Box\RequirementChecker; use PHPUnit\Framework\TestCase; -use function json_decode; +use function Safe\json_decode; /** * @covers \KevinGH\Box\RequirementChecker\DecodedComposerLock diff --git a/vendor-bin/rector/composer.json b/vendor-bin/rector/composer.json index 80a436601..e829b1ed6 100644 --- a/vendor-bin/rector/composer.json +++ b/vendor-bin/rector/composer.json @@ -1,5 +1,5 @@ { "require-dev": { - "rector/rector": "^0.14" + "rector/rector": ">=0.14" } } From ffbe9e6d6b5145ec7580fa3ce165c29a822e2028 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 21 Nov 2023 22:26:23 +0100 Subject: [PATCH 02/12] fix --- src/Annotation/DocblockAnnotationParser.php | 6 +- src/Box.php | 6 +- src/Compactor/Compactors.php | 2 +- src/Compactor/FileExtensionCompactor.php | 2 +- src/Compactor/Php.php | 2 +- src/Compactor/PhpScoper.php | 2 +- src/Compactor/Placeholder.php | 2 +- src/Composer/CompilerPsrLogger.php | 2 +- src/Composer/ComposerFile.php | 4 +- src/Composer/ComposerFiles.php | 8 +-- src/Composer/ComposerOrchestrator.php | 6 +- src/Composer/ComposerProcessFactory.php | 6 +- src/Configuration/Configuration.php | 70 +++++++++---------- src/Configuration/ConfigurationLoader.php | 4 +- src/Configuration/ExportableConfiguration.php | 70 +++++++++---------- src/Console/Application.php | 43 +++++++----- src/Console/Command/Compile.php | 2 +- src/Console/Logger/CompilerLogger.php | 4 +- src/Console/PharInfoRenderer.php | 3 +- src/Console/Php/PhpSettingsHandler.php | 4 +- src/DockerFileGenerator.php | 4 +- src/Json/Json.php | 2 +- src/Json/JsonValidationException.php | 4 +- src/MapFile.php | 2 +- src/Phar/Differ/ChecksumDiffer.php | 2 +- src/Phar/Differ/ProcessCommandBasedDiffer.php | 2 +- src/Phar/PharInfo.php | 10 +-- src/Phar/PharMeta.php | 20 +++--- src/PharInfo/PharInfo.php | 2 +- src/PhpScoper/ExcludedFilesScoper.php | 4 +- src/PhpScoper/SerializablePatcher.php | 2 +- src/PhpScoper/SerializableScoper.php | 2 +- .../DecodedComposerJson.php | 4 +- .../DecodedComposerLock.php | 4 +- src/RequirementChecker/PackageInfo.php | 4 +- src/RequirementChecker/RequiredItem.php | 4 +- src/RequirementChecker/Requirement.php | 12 ++-- tests/Console/Command/ExtractTest.php | 10 +-- tests/Phar/PharMetaTest.php | 34 ++++----- 39 files changed, 193 insertions(+), 183 deletions(-) diff --git a/src/Annotation/DocblockAnnotationParser.php b/src/Annotation/DocblockAnnotationParser.php index b53fb1cce..bb12a6ed6 100644 --- a/src/Annotation/DocblockAnnotationParser.php +++ b/src/Annotation/DocblockAnnotationParser.php @@ -33,14 +33,14 @@ final class DocblockAnnotationParser /** * @var array */ - private array $ignoredAnnotationsAsKeys; + private readonly array $ignoredAnnotationsAsKeys; /** * @param string[] $ignoredAnnotations */ public function __construct( - private DocBlockFactoryInterface $factory, - private Formatter $tagsFormatter, + private readonly DocBlockFactoryInterface $factory, + private readonly Formatter $tagsFormatter, array $ignoredAnnotations, ) { $this->ignoredAnnotationsAsKeys = array_flip($ignoredAnnotations); diff --git a/src/Box.php b/src/Box.php index 04581a4d0..969e1b05b 100644 --- a/src/Box.php +++ b/src/Box.php @@ -456,12 +456,12 @@ private function processContents(array $files): array // Keep the fully qualified call here since this function may be executed without the right autoloading // mechanism - \KevinGH\Box\register_aliases(); + register_aliases(); if (true === \KevinGH\Box\is_parallel_processing_enabled()) { - \KevinGH\Box\register_error_handler(); + register_error_handler(); } - $contents = \Fidry\FileSystem\FS::getFileContents($file); + $contents = FS::getFileContents($file); $local = $mapFile($file); diff --git a/src/Compactor/Compactors.php b/src/Compactor/Compactors.php index f96bc2e60..9a58f0011 100644 --- a/src/Compactor/Compactors.php +++ b/src/Compactor/Compactors.php @@ -28,7 +28,7 @@ final class Compactors implements Compactor, Countable /** * @var Compactor[] */ - private array $compactors; + private readonly array $compactors; private ?PhpScoper $scoperCompactor = null; diff --git a/src/Compactor/FileExtensionCompactor.php b/src/Compactor/FileExtensionCompactor.php index 4c62dbb8d..15fdce28c 100644 --- a/src/Compactor/FileExtensionCompactor.php +++ b/src/Compactor/FileExtensionCompactor.php @@ -29,7 +29,7 @@ abstract class FileExtensionCompactor extends BaseCompactor /** * @var string[] */ - private array $extensions; + private readonly array $extensions; /** * @param string[] $extensions the list of supported file extensions diff --git a/src/Compactor/Php.php b/src/Compactor/Php.php index 216198ee5..acccd786a 100644 --- a/src/Compactor/Php.php +++ b/src/Compactor/Php.php @@ -47,7 +47,7 @@ final class Php extends FileExtensionCompactor { public function __construct( - private ?DocblockAnnotationParser $annotationParser, + private readonly ?DocblockAnnotationParser $annotationParser, array $extensions = ['php'], ) { parent::__construct($extensions); diff --git a/src/Compactor/PhpScoper.php b/src/Compactor/PhpScoper.php index a2b410e5f..bd6e2f09d 100644 --- a/src/Compactor/PhpScoper.php +++ b/src/Compactor/PhpScoper.php @@ -20,7 +20,7 @@ /** * @private */ -final class PhpScoper implements Compactor +final readonly class PhpScoper implements Compactor { public function __construct(private Scoper $scoper) { diff --git a/src/Compactor/Placeholder.php b/src/Compactor/Placeholder.php index 66f66835e..91b0f3f4b 100644 --- a/src/Compactor/Placeholder.php +++ b/src/Compactor/Placeholder.php @@ -23,7 +23,7 @@ final class Placeholder implements Compactor /** * @var scalar[] */ - private array $placeholders; + private readonly array $placeholders; /** * @param scalar[] $placeholders diff --git a/src/Composer/CompilerPsrLogger.php b/src/Composer/CompilerPsrLogger.php index fdd52fdca..8f2ede149 100644 --- a/src/Composer/CompilerPsrLogger.php +++ b/src/Composer/CompilerPsrLogger.php @@ -24,7 +24,7 @@ final class CompilerPsrLogger extends AbstractLogger { public function __construct( - private CompilerLogger $decoratedLogger, + private readonly CompilerLogger $decoratedLogger, ) { } diff --git a/src/Composer/ComposerFile.php b/src/Composer/ComposerFile.php index 1d362361b..dc8a96cea 100644 --- a/src/Composer/ComposerFile.php +++ b/src/Composer/ComposerFile.php @@ -18,8 +18,8 @@ final class ComposerFile { - private ?string $path; - private array $contents; + private readonly ?string $path; + private readonly array $contents; public static function createEmpty(): self { diff --git a/src/Composer/ComposerFiles.php b/src/Composer/ComposerFiles.php index 79a36ab14..9a239043d 100644 --- a/src/Composer/ComposerFiles.php +++ b/src/Composer/ComposerFiles.php @@ -18,7 +18,7 @@ use function array_map; use function array_values; -final class ComposerFiles +final readonly class ComposerFiles { public static function createEmpty(): self { @@ -30,9 +30,9 @@ public static function createEmpty(): self } public function __construct( - private readonly ComposerFile $composerJson, - private readonly ComposerFile $composerLock, - private readonly ComposerFile $installedJson, + private ComposerFile $composerJson, + private ComposerFile $composerLock, + private ComposerFile $installedJson, ) { } diff --git a/src/Composer/ComposerOrchestrator.php b/src/Composer/ComposerOrchestrator.php index 02c7f74ed..91f6c40ea 100644 --- a/src/Composer/ComposerOrchestrator.php +++ b/src/Composer/ComposerOrchestrator.php @@ -48,9 +48,9 @@ public static function create(): self } public function __construct( - private ComposerProcessFactory $processFactory, - private LoggerInterface $logger, - private FileSystem $fileSystem, + private readonly ComposerProcessFactory $processFactory, + private readonly LoggerInterface $logger, + private readonly FileSystem $fileSystem, ) { } diff --git a/src/Composer/ComposerProcessFactory.php b/src/Composer/ComposerProcessFactory.php index 1cfbb8878..1ff3abdc2 100644 --- a/src/Composer/ComposerProcessFactory.php +++ b/src/Composer/ComposerProcessFactory.php @@ -49,10 +49,10 @@ public static function create( * @param Closure():string $composerExecutableFactory */ public function __construct( - private Closure $composerExecutableFactory, + private readonly Closure $composerExecutableFactory, private ?string $verbosity, - private bool $ansi, - private array $defaultEnvironmentVariables, + private readonly bool $ansi, + private readonly array $defaultEnvironmentVariables, ) { } diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 9d28de0fa..ddf0a2884 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -213,8 +213,8 @@ final class Configuration private const STUB_KEY = 'stub'; private const TIMESTAMP = 'timestamp'; - private ?string $mainScriptPath; - private ?string $mainScriptContents; + private readonly ?string $mainScriptPath; + private readonly ?string $mainScriptContents; private ?string $composerBin = null; public static function create(?string $file, stdClass $raw): self @@ -422,41 +422,41 @@ public static function create(?string $file, stdClass $raw): self * @param string[] $recommendations */ private function __construct( - private ?string $file, - private string $alias, - private string $basePath, - private ComposerFile $composerJson, - private ComposerFile $composerLock, - private array $files, - private array $binaryFiles, - private bool $autodiscoveredFiles, - private bool $dumpAutoload, - private bool $excludeComposerFiles, - private bool $excludeDevFiles, - private Compactors|array $compactors, - private CompressionAlgorithm $compressionAlgorithm, - private int|string|null $fileMode, + private readonly ?string $file, + private readonly string $alias, + private readonly string $basePath, + private readonly ComposerFile $composerJson, + private readonly ComposerFile $composerLock, + private readonly array $files, + private readonly array $binaryFiles, + private readonly bool $autodiscoveredFiles, + private readonly bool $dumpAutoload, + private readonly bool $excludeComposerFiles, + private readonly bool $excludeDevFiles, + private readonly Compactors|array $compactors, + private readonly CompressionAlgorithm $compressionAlgorithm, + private readonly int|string|null $fileMode, ?string $mainScriptPath, ?string $mainScriptContents, - private MapFile $fileMapper, - private mixed $metadata, - private string $tmpOutputPath, - private string $outputPath, - private ?string $privateKeyPassphrase, - private ?string $privateKeyPath, - private bool $promptForPrivateKey, - private array $processedReplacements, - private ?string $shebang, - private SigningAlgorithm $signingAlgorithm, - private ?string $stubBannerContents, - private ?string $stubBannerPath, - private ?string $stubPath, - private bool $isInterceptFileFuncs, - private bool $isStubGenerated, - private ?DateTimeImmutable $timestamp, - private bool $checkRequirements, - private array $warnings, - private array $recommendations, + private readonly MapFile $fileMapper, + private readonly mixed $metadata, + private readonly string $tmpOutputPath, + private readonly string $outputPath, + private readonly ?string $privateKeyPassphrase, + private readonly ?string $privateKeyPath, + private readonly bool $promptForPrivateKey, + private readonly array $processedReplacements, + private readonly ?string $shebang, + private readonly SigningAlgorithm $signingAlgorithm, + private readonly ?string $stubBannerContents, + private readonly ?string $stubBannerPath, + private readonly ?string $stubPath, + private readonly bool $isInterceptFileFuncs, + private readonly bool $isStubGenerated, + private readonly ?DateTimeImmutable $timestamp, + private readonly bool $checkRequirements, + private readonly array $warnings, + private readonly array $recommendations, ) { if (null === $mainScriptPath) { Assert::null($mainScriptContents); diff --git a/src/Configuration/ConfigurationLoader.php b/src/Configuration/ConfigurationLoader.php index 81405c65d..6a2dabd1b 100644 --- a/src/Configuration/ConfigurationLoader.php +++ b/src/Configuration/ConfigurationLoader.php @@ -20,11 +20,11 @@ /** * @private */ -final class ConfigurationLoader +final readonly class ConfigurationLoader { private const SCHEMA_FILE = __DIR__.'/../../res/schema.json'; - public function __construct(private readonly Json $json = new Json()) + public function __construct(private Json $json = new Json()) { } diff --git a/src/Configuration/ExportableConfiguration.php b/src/Configuration/ExportableConfiguration.php index 2bc2ff595..a4151acb6 100644 --- a/src/Configuration/ExportableConfiguration.php +++ b/src/Configuration/ExportableConfiguration.php @@ -34,7 +34,7 @@ * * @internal */ -final class ExportableConfiguration +final readonly class ExportableConfiguration { public static function create(Configuration $configuration): self { @@ -114,40 +114,40 @@ private static function createPathNormalizer(string $basePath): Closure /** @noinspection PhpPropertyOnlyWrittenInspection */ private function __construct( - private readonly ?string $file, - private readonly string $alias, - private readonly string $basePath, - private readonly ComposerFile $composerJson, - private readonly ComposerFile $composerLock, - private readonly array $files, - private readonly array $binaryFiles, - private readonly bool $autodiscoveredFiles, - private readonly bool $dumpAutoload, - private readonly bool $excludeComposerFiles, - private readonly bool $excludeDevFiles, - private readonly Compactors|array $compactors, - private readonly string $compressionAlgorithm, - private readonly int|string|null $fileMode, - private readonly ?string $mainScriptPath, - private readonly ?string $mainScriptContents, - private readonly MapFile $fileMapper, - private readonly mixed $metadata, - private readonly string $tmpOutputPath, - private readonly string $outputPath, - private readonly ?string $privateKeyPassphrase, - private readonly ?string $privateKeyPath, - private readonly bool $promptForPrivateKey, - private readonly array $processedReplacements, - private readonly ?string $shebang, - private readonly string $signingAlgorithm, - private readonly ?string $stubBannerContents, - private readonly ?string $stubBannerPath, - private readonly ?string $stubPath, - private readonly bool $isInterceptFileFuncs, - private readonly bool $isStubGenerated, - private readonly bool $checkRequirements, - private readonly array $warnings, - private readonly array $recommendations, + private ?string $file, + private string $alias, + private string $basePath, + private ComposerFile $composerJson, + private ComposerFile $composerLock, + private array $files, + private array $binaryFiles, + private bool $autodiscoveredFiles, + private bool $dumpAutoload, + private bool $excludeComposerFiles, + private bool $excludeDevFiles, + private Compactors|array $compactors, + private string $compressionAlgorithm, + private int|string|null $fileMode, + private ?string $mainScriptPath, + private ?string $mainScriptContents, + private MapFile $fileMapper, + private mixed $metadata, + private string $tmpOutputPath, + private string $outputPath, + private ?string $privateKeyPassphrase, + private ?string $privateKeyPath, + private bool $promptForPrivateKey, + private array $processedReplacements, + private ?string $shebang, + private string $signingAlgorithm, + private ?string $stubBannerContents, + private ?string $stubBannerPath, + private ?string $stubPath, + private bool $isInterceptFileFuncs, + private bool $isStubGenerated, + private bool $checkRequirements, + private array $warnings, + private array $recommendations, ) { } diff --git a/src/Console/Application.php b/src/Console/Application.php index 47d6e209b..193959766 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -15,6 +15,17 @@ namespace KevinGH\Box\Console; use Fidry\Console\Application\Application as FidryApplication; +use KevinGH\Box\Console\Command\Compile; +use KevinGH\Box\Console\Command\Composer\ComposerCheckVersion; +use KevinGH\Box\Console\Command\Composer\ComposerVendorDir; +use KevinGH\Box\Console\Command\Diff; +use KevinGH\Box\Console\Command\Extract; +use KevinGH\Box\Console\Command\GenerateDockerFile; +use KevinGH\Box\Console\Command\Info; +use KevinGH\Box\Console\Command\Namespace_; +use KevinGH\Box\Console\Command\Process; +use KevinGH\Box\Console\Command\Validate; +use KevinGH\Box\Console\Command\Verify; use function KevinGH\Box\get_box_version; use function sprintf; use function trim; @@ -24,16 +35,16 @@ */ final class Application implements FidryApplication { - private string $version; - private string $releaseDate; + private readonly string $version; + private readonly string $releaseDate; private string $header; public function __construct( - private string $name = 'Box', + private readonly string $name = 'Box', ?string $version = null, string $releaseDate = '@release-date@', - private bool $autoExit = true, - private bool $catchExceptions = true, + private readonly bool $autoExit = true, + private readonly bool $catchExceptions = true, ) { $this->version = $version ?? get_box_version(); $this->releaseDate = !str_contains($releaseDate, '@') ? $releaseDate : ''; @@ -78,17 +89,17 @@ public function getHeader(): string public function getCommands(): array { return [ - new Command\Composer\ComposerCheckVersion(), - new Command\Composer\ComposerVendorDir(), - new Command\Compile($this->getHeader()), - new Command\Diff(), - new Command\Info(), - new Command\Process(), - new Command\Extract(), - new Command\Validate(), - new Command\Verify(), - new Command\GenerateDockerFile(), - new Command\Namespace_(), + new ComposerCheckVersion(), + new ComposerVendorDir(), + new Compile($this->getHeader()), + new Diff(), + new Info(), + new Process(), + new Extract(), + new Validate(), + new Verify(), + new GenerateDockerFile(), + new Namespace_(), ]; } diff --git a/src/Console/Command/Compile.php b/src/Console/Command/Compile.php index 8d5f3c208..9aa49bca4 100644 --- a/src/Console/Command/Compile.php +++ b/src/Console/Command/Compile.php @@ -112,7 +112,7 @@ final class Compile implements CommandAware private const DEBUG_DIR = '.box_dump'; - public function __construct(private string $header) + public function __construct(private readonly string $header) { } diff --git a/src/Console/Logger/CompilerLogger.php b/src/Console/Logger/CompilerLogger.php index 5b19775f5..2cd3bc034 100644 --- a/src/Console/Logger/CompilerLogger.php +++ b/src/Console/Logger/CompilerLogger.php @@ -22,7 +22,7 @@ /** * @internal */ -final class CompilerLogger +final readonly class CompilerLogger { public const QUESTION_MARK_PREFIX = '?'; public const STAR_PREFIX = '*'; @@ -30,7 +30,7 @@ final class CompilerLogger public const MINUS_PREFIX = '-'; public const CHEVRON_PREFIX = '>'; - public function __construct(private readonly IO $io) + public function __construct(private IO $io) { } diff --git a/src/Console/PharInfoRenderer.php b/src/Console/PharInfoRenderer.php index d895cc85c..168eca760 100644 --- a/src/Console/PharInfoRenderer.php +++ b/src/Console/PharInfoRenderer.php @@ -34,7 +34,6 @@ use function count; use function implode; use function is_array; -use function KevinGH\Box\format_size; use function KevinGH\Box\format_size as format_size1; use function KevinGH\Box\noop; use function key; @@ -256,7 +255,7 @@ public static function renderContentsSummary(PharInfo $pharInfo, IO $io): void sprintf( 'Contents:%s (%s)', 1 === $totalCount ? ' 1 file' : " {$totalCount} files", - format_size( + format_size1( filesize($pharInfo->getFile()), ), ), diff --git a/src/Console/Php/PhpSettingsHandler.php b/src/Console/Php/PhpSettingsHandler.php index ccec96722..f26804861 100644 --- a/src/Console/Php/PhpSettingsHandler.php +++ b/src/Console/Php/PhpSettingsHandler.php @@ -34,8 +34,8 @@ */ final class PhpSettingsHandler extends XdebugHandler { - private LoggerInterface $logger; - private bool $pharReadonly; + private readonly LoggerInterface $logger; + private readonly bool $pharReadonly; public function __construct(LoggerInterface $logger) { diff --git a/src/DockerFileGenerator.php b/src/DockerFileGenerator.php index f8ae840a9..39c36b2f4 100644 --- a/src/DockerFileGenerator.php +++ b/src/DockerFileGenerator.php @@ -55,12 +55,12 @@ final class DockerFileGenerator '7.0.0' => '7-cli-alpine', ]; - private string $image; + private readonly string $image; /** * @var string[] */ - private array $extensions; + private readonly array $extensions; /** * Creates a new instance of the generator. diff --git a/src/Json/Json.php b/src/Json/Json.php index a49b999fd..823c0881f 100644 --- a/src/Json/Json.php +++ b/src/Json/Json.php @@ -28,7 +28,7 @@ /** * @private */ -final class Json +final readonly class Json { private JsonParser $linter; diff --git a/src/Json/JsonValidationException.php b/src/Json/JsonValidationException.php index 288837755..2e6990f6a 100644 --- a/src/Json/JsonValidationException.php +++ b/src/Json/JsonValidationException.php @@ -23,8 +23,8 @@ */ final class JsonValidationException extends UnexpectedValueException { - private ?string $validatedFile; - private array $errors; + private readonly ?string $validatedFile; + private readonly array $errors; /** * @param string[] $errors diff --git a/src/MapFile.php b/src/MapFile.php index 2bedefd79..bf23c7507 100644 --- a/src/MapFile.php +++ b/src/MapFile.php @@ -23,7 +23,7 @@ * * @private */ -final class MapFile +final readonly class MapFile { /** * @param string[][] $map diff --git a/src/Phar/Differ/ChecksumDiffer.php b/src/Phar/Differ/ChecksumDiffer.php index 06121135d..02c59e57e 100644 --- a/src/Phar/Differ/ChecksumDiffer.php +++ b/src/Phar/Differ/ChecksumDiffer.php @@ -21,7 +21,7 @@ use function hash; use function implode; -final class ChecksumDiffer implements Differ +final readonly class ChecksumDiffer implements Differ { public function __construct( private string $checksumAlgorithm, diff --git a/src/Phar/Differ/ProcessCommandBasedDiffer.php b/src/Phar/Differ/ProcessCommandBasedDiffer.php index eab2442a1..ba820877b 100644 --- a/src/Phar/Differ/ProcessCommandBasedDiffer.php +++ b/src/Phar/Differ/ProcessCommandBasedDiffer.php @@ -18,7 +18,7 @@ use KevinGH\Box\Phar\PharInfo; use Symfony\Component\Process\Process; -final class ProcessCommandBasedDiffer implements Differ +final readonly class ProcessCommandBasedDiffer implements Differ { public function __construct(private string $command) { diff --git a/src/Phar/PharInfo.php b/src/Phar/PharInfo.php index ed10a7e0a..7fee1f6c1 100644 --- a/src/Phar/PharInfo.php +++ b/src/Phar/PharInfo.php @@ -80,16 +80,16 @@ final class PharInfo private static string $stubfile; private static string $phpExecutable; - private PharMeta $meta; - private string $tmp; - private string $file; - private string $fileName; + private readonly PharMeta $meta; + private readonly string $tmp; + private readonly string $file; + private readonly string $fileName; private array $compressionCount; /** * @var array */ - private array $files; + private readonly array $files; public function __construct(string $file) { diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index 3aea0927b..a998888d6 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -37,7 +37,7 @@ * * @private */ -final class PharMeta +final readonly class PharMeta { /** * @param non-empty-string|null $stub @@ -47,15 +47,15 @@ final class PharMeta * @param array $filesMeta */ public function __construct( - public readonly CompressionAlgorithm $compression, + public CompressionAlgorithm $compression, #[ArrayShape(['hash' => 'string', 'hash_type' => 'string'])] - public readonly ?array $signature, - public readonly ?string $stub, - public readonly ?string $version, - public readonly ?string $normalizedMetadata, - public readonly int $timestamp, - public readonly ?string $pubKeyContent, - public readonly array $filesMeta, + public ?array $signature, + public ?string $stub, + public ?string $version, + public ?string $normalizedMetadata, + public int $timestamp, + public ?string $pubKeyContent, + public array $filesMeta, ) { } @@ -114,7 +114,7 @@ public function toJson(): string 'timestamp' => $this->timestamp, 'pubKeyContent' => $this->pubKeyContent, 'filesMeta' => $this->filesMeta, - ]); + ], JSON_THROW_ON_ERROR); } /** diff --git a/src/PharInfo/PharInfo.php b/src/PharInfo/PharInfo.php index 71bbffa84..e36530c54 100644 --- a/src/PharInfo/PharInfo.php +++ b/src/PharInfo/PharInfo.php @@ -27,7 +27,7 @@ */ final class PharInfo { - private NewPharInfo $decoratedPharInfo; + private readonly NewPharInfo $decoratedPharInfo; private PharData|Phar $phar; diff --git a/src/PhpScoper/ExcludedFilesScoper.php b/src/PhpScoper/ExcludedFilesScoper.php index fd3c8f90c..b99f3e69a 100644 --- a/src/PhpScoper/ExcludedFilesScoper.php +++ b/src/PhpScoper/ExcludedFilesScoper.php @@ -21,10 +21,10 @@ final class ExcludedFilesScoper implements PhpScoperScoper { - private array $excludedFilePathsAsKeys; + private readonly array $excludedFilePathsAsKeys; public function __construct( - private PhpScoperScoper $decoratedScoper, + private readonly PhpScoperScoper $decoratedScoper, string ...$excludedFilePaths, ) { $this->excludedFilePathsAsKeys = array_flip($excludedFilePaths); diff --git a/src/PhpScoper/SerializablePatcher.php b/src/PhpScoper/SerializablePatcher.php index 14f51d7c0..c436b3b61 100644 --- a/src/PhpScoper/SerializablePatcher.php +++ b/src/PhpScoper/SerializablePatcher.php @@ -22,7 +22,7 @@ /** * @var PatcherCallable = (string $filePath, string $prefix, string $contents): string */ -final class SerializablePatcher implements Patcher +final readonly class SerializablePatcher implements Patcher { public static function create(callable $patcher): self { diff --git a/src/PhpScoper/SerializableScoper.php b/src/PhpScoper/SerializableScoper.php index 152c00e87..d9b845a0d 100644 --- a/src/PhpScoper/SerializableScoper.php +++ b/src/PhpScoper/SerializableScoper.php @@ -25,7 +25,7 @@ */ final class SerializableScoper implements Scoper { - private PhpScoperConfiguration $scoperConfig; + private readonly PhpScoperConfiguration $scoperConfig; private PhpScoperContainer $scoperContainer; private PhpScoperScoper $scoper; private SymbolsRegistry $symbolsRegistry; diff --git a/src/RequirementChecker/DecodedComposerJson.php b/src/RequirementChecker/DecodedComposerJson.php index 01e0fb953..326882a9b 100644 --- a/src/RequirementChecker/DecodedComposerJson.php +++ b/src/RequirementChecker/DecodedComposerJson.php @@ -19,12 +19,12 @@ /** * @private */ -final class DecodedComposerJson +final readonly class DecodedComposerJson { /** * @param array $composerJsonDecodedContents Decoded JSON contents of the `composer.json` file */ - public function __construct(private readonly array $composerJsonDecodedContents) + public function __construct(private array $composerJsonDecodedContents) { } diff --git a/src/RequirementChecker/DecodedComposerLock.php b/src/RequirementChecker/DecodedComposerLock.php index ba5d7f473..651b64527 100644 --- a/src/RequirementChecker/DecodedComposerLock.php +++ b/src/RequirementChecker/DecodedComposerLock.php @@ -19,12 +19,12 @@ /** * @private */ -final class DecodedComposerLock +final readonly class DecodedComposerLock { /** * @param array $composerLockDecodedContents Decoded JSON contents of the `composer.lock` file */ - public function __construct(private readonly array $composerLockDecodedContents) + public function __construct(private array $composerLockDecodedContents) { } diff --git a/src/RequirementChecker/PackageInfo.php b/src/RequirementChecker/PackageInfo.php index 3ff05aa25..5f4fbf8ad 100644 --- a/src/RequirementChecker/PackageInfo.php +++ b/src/RequirementChecker/PackageInfo.php @@ -19,7 +19,7 @@ /** * @private */ -final class PackageInfo +final readonly class PackageInfo { private const EXTENSION_REGEX = '/^ext-(?.+)$/'; @@ -37,7 +37,7 @@ final class PackageInfo private const SYMFONY_POLYFILL_REGEX = '/symfony\/polyfill-(?.+)/'; - public function __construct(private readonly array $packageInfo) + public function __construct(private array $packageInfo) { } diff --git a/src/RequirementChecker/RequiredItem.php b/src/RequirementChecker/RequiredItem.php index 5bd38e19e..9036d426b 100644 --- a/src/RequirementChecker/RequiredItem.php +++ b/src/RequirementChecker/RequiredItem.php @@ -20,7 +20,7 @@ /** * @private */ -final class RequiredItem +final readonly class RequiredItem { private const POLYFILL_MAP = [ 'paragonie/sodium_compat' => 'libsodium', @@ -32,7 +32,7 @@ final class RequiredItem /** * @param array $packageInfo */ - public function __construct(private readonly array $packageInfo) + public function __construct(private array $packageInfo) { } diff --git a/src/RequirementChecker/Requirement.php b/src/RequirementChecker/Requirement.php index 73feb9a7d..fe1d8e3ef 100644 --- a/src/RequirementChecker/Requirement.php +++ b/src/RequirementChecker/Requirement.php @@ -17,14 +17,14 @@ /** * @private */ -final class Requirement +final readonly class Requirement { public function __construct( - public readonly RequirementType $type, - public readonly string $condition, - public readonly ?string $source, - public readonly string $message, - public readonly string $helpMessage, + public RequirementType $type, + public string $condition, + public ?string $source, + public string $message, + public string $helpMessage, ) { } diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index cd7aa24af..b86d3c659 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -84,7 +84,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1559806605, + 1_559_806_605, null, [ '.hidden' => [ @@ -131,7 +131,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1559807994, + 1_559_807_994, null, [ '.hidden' => [ @@ -160,7 +160,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531272, + 1_374_531_272, null, [ 'index.php' => [ @@ -189,7 +189,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531313, + 1_374_531_313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -324,7 +324,7 @@ public function test_it_cannot_extract_an_invalid_phar(string $pharPath): void ); self::assertSame(ExitCode::FAILURE, $this->commandTester->getStatusCode()); - } catch (InvalidPhar $exception) { + } catch (InvalidPhar) { // Continue } diff --git a/tests/Phar/PharMetaTest.php b/tests/Phar/PharMetaTest.php index 7dde21c9a..8396776c8 100644 --- a/tests/Phar/PharMetaTest.php +++ b/tests/Phar/PharMetaTest.php @@ -47,7 +47,7 @@ public static function pharMetaProvider(): iterable null, null, null, - 1509920675, + 1_509_920_675, null, [], ), @@ -64,7 +64,7 @@ public static function pharMetaProvider(): iterable 'action' => 'sayHello', ) EOL, - 1509920675, + 1_509_920_675, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -123,7 +123,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680285013, + 1_680_285_013, null, [ 'sample.php' => [ @@ -146,7 +146,7 @@ public static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1509920675, + 1_509_920_675, null, [ 'foo.php' => [ @@ -169,7 +169,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680680933, + 1_680_680_933, null, [ 'sample.php' => [ @@ -197,7 +197,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680469485, + 1_680_469_485, null, [ 'sample.php' => [ @@ -222,7 +222,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680469504, + 1_680_469_504, null, [ 'sample.php' => [ @@ -246,7 +246,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531272, + 1_374_531_272, null, [ 'index.php' => [ @@ -269,7 +269,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531313, + 1_374_531_313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -298,7 +298,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', "'Hello world!'", - 1680366918, + 1_680_366_918, null, [ 'sample.php' => [ @@ -321,7 +321,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', '-19.8', - 1680366947, + 1_680_366_947, null, [ 'sample.php' => [ @@ -348,7 +348,7 @@ public static function pharProvider(): iterable 'action' => 'sayHello', ) EOL, - 1680367053, + 1_680_367_053, null, [ 'sample.php' => [ @@ -368,7 +368,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284754, + 1_680_284_754, null, [ 'sample.txt' => [ @@ -389,7 +389,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284663, + 1_680_284_663, null, [ 'sample.txt' => [ @@ -411,7 +411,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284660, + 1_680_284_660, null, [ 'sample.txt' => [ @@ -433,7 +433,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284663, + 1_680_284_663, null, [ 'sample.txt' => [ @@ -457,7 +457,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680645848, + 1_680_645_848, null, [ '.hidden-dir/.hidden-file' => [ From 62fb2f29a3c583e57d60473b182c7d25e3063ac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 21 Nov 2023 22:43:09 +0100 Subject: [PATCH 03/12] add rector --- Makefile | 3 +++ requirement-checker/Makefile | 32 ++++++++++++++++++++++++++-- requirement-checker/rector-src.php | 25 ++++++++++++++++++++++ requirement-checker/rector-tests.php | 23 ++++++++++++++++++++ requirement-checker/src/Checker.php | 2 +- 5 files changed, 82 insertions(+), 3 deletions(-) create mode 100644 requirement-checker/rector-src.php create mode 100644 requirement-checker/rector-tests.php diff --git a/Makefile b/Makefile index 1fe7f0324..de4148a1d 100644 --- a/Makefile +++ b/Makefile @@ -365,6 +365,9 @@ vendor-bin/php-cs-fixer/composer.lock: vendor-bin/php-cs-fixer/composer.json @echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)" @echo "$$ composer bin php-cs-fixer update --lock && touch -c $(@)" +.PHONY: rector_install +rector_install: $(RECTOR_BIN) + $(RECTOR_BIN): vendor-bin/rector/vendor touch -c $@ vendor-bin/rector/vendor: vendor-bin/rector/composer.lock $(COMPOSER_BIN_PLUGIN_VENDOR) diff --git a/requirement-checker/Makefile b/requirement-checker/Makefile index 26eaef625..10c5e3f46 100644 --- a/requirement-checker/Makefile +++ b/requirement-checker/Makefile @@ -26,6 +26,9 @@ PHAR_EXTRACT = ../res/requirement-checker BOX_BIN = ../bin/box BOX = $(BOX_BIN) +RECTOR_BIN = ../vendor-bin/rector/vendor/bin/rector +RECTOR = $(RECTOR_BIN) + DIFF = diff --strip-trailing-cr --ignore-all-space --side-by-side --suppress-common-lines @@ -109,11 +112,11 @@ phpunit_autoreview: $(PHPUNIT_BIN) vendor .PHONY: cs cs: ## Fixes CS -cs: gitignore_sort composer_normalize php_cs_fixer +cs: gitignore_sort composer_normalize rector php_cs_fixer .PHONY: cs_lint cs_lint: ## Checks CS -cs_lint: composer_normalize_lint php_cs_fixer_lint +cs_lint: composer_normalize_lint rector_lint php_cs_fixer_lint .PHONY: gitignore_sort gitignore_sort: @@ -135,6 +138,28 @@ php_cs_fixer: $(PHP_CS_FIXER_BIN) php_cs_fixer_lint: $(PHP_CS_FIXER_BIN) $(PHP_CS_FIXER) fix --ansi --verbose --dry-run --diff +.PHONY: rector +rector: rector_src rector_tests + +.PHONY: rector_src +rector_src: $(RECTOR_BIN) + $(RECTOR) --config=rector-src.php + +.PHONY: rector_tests +rector_tests: $(RECTOR_BIN) + $(RECTOR) --config=rector-tests.php + +.PHONY: rector_lint +rector_lint: rector_lint_src rector_lint_tests + +.PHONY: rector_lint_src +rector_lint_src: $(RECTOR_BIN) + $(RECTOR) --config=rector-src.php --dry-run + +.PHONY: rector_lint_tests +rector_lint_tests: $(RECTOR_BIN) + $(RECTOR) --config=rector-tests.php --dry-run + # # Tests @@ -240,3 +265,6 @@ $(PHAR_EXTRACT): $(PHAR) $(BOX_BIN) $(BOX_BIN): cd ..; $(MAKE) --file=Makefile bin/box + +$(RECTOR_BIN): + cd ..; $(MAKE) --file=Makefile rector_install diff --git a/requirement-checker/rector-src.php b/requirement-checker/rector-src.php new file mode 100644 index 000000000..ddf482591 --- /dev/null +++ b/requirement-checker/rector-src.php @@ -0,0 +1,25 @@ +paths([ + __DIR__ . '/src', + ]); + + $rectorConfig->autoloadPaths([ + __DIR__ . '/vendor/autoload.php', + __DIR__ . '/../vendor-bin/rector/vendor/autoload.php', + ]); + + $rectorConfig->importNames(); + + $rectorConfig->sets([ + // TODO + // DowngradeLevelSetList::DOWN_TO_PHP_72, + ]); +}; diff --git a/requirement-checker/rector-tests.php b/requirement-checker/rector-tests.php new file mode 100644 index 000000000..adda3dbce --- /dev/null +++ b/requirement-checker/rector-tests.php @@ -0,0 +1,23 @@ +paths([ + __DIR__ . '/tests', + ]); + + $rectorConfig->autoloadPaths([ + __DIR__ . '/vendor/autoload.php', + __DIR__ . '/../vendor-bin/rector/vendor/autoload.php', + ]); + + $rectorConfig->importNames(); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_82, + ]); +}; diff --git a/requirement-checker/src/Checker.php b/requirement-checker/src/Checker.php index 91c0dc7b1..50de78732 100644 --- a/requirement-checker/src/Checker.php +++ b/requirement-checker/src/Checker.php @@ -170,7 +170,7 @@ private static function createCondition($type, $condition): IsFulfilled throw new InvalidArgumentException( sprintf( 'Unknown requirement type "%s".', - $type, + $type ), ); } From 6a09fd6eaecfffff4cbea0809d5d0d6ff7617e4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 21 Nov 2023 22:44:09 +0100 Subject: [PATCH 04/12] fix --- requirement-checker/tests/CheckerTest.php | 102 ++++++++---------- requirement-checker/tests/RequirementTest.php | 2 +- 2 files changed, 48 insertions(+), 56 deletions(-) diff --git a/requirement-checker/tests/CheckerTest.php b/requirement-checker/tests/CheckerTest.php index ea8f7cd85..416f88de9 100644 --- a/requirement-checker/tests/CheckerTest.php +++ b/requirement-checker/tests/CheckerTest.php @@ -64,89 +64,81 @@ public function provideRequirements(): iterable $phpVersion = PHP_VERSION; $remainingVerbosities = ['verbosity=verbose' => IO::VERBOSITY_VERBOSE, 'verbosity=normal' => IO::VERBOSITY_NORMAL, 'verbosity=quiet' => IO::VERBOSITY_QUIET]; - yield 'no requirement; verbosity=debug' => (static function () use ($phpVersion) { - return [ - new RequirementCollection(), - IO::VERBOSITY_DEBUG, - true, - << (static fn () => [ + new RequirementCollection(), + IO::VERBOSITY_DEBUG, + true, + << Using PHP {$phpVersion} - > PHP is using the following php.ini file: - /path/to/php.ini + > Using PHP {$phpVersion} + > PHP is using the following php.ini file: + /path/to/php.ini - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ]; - })(); + EOF + ])(); - yield 'no requirement + no ini path; verbosity=debug' => (static function () use ($phpVersion) { - return [ - new RequirementCollection(false), - IO::VERBOSITY_DEBUG, - true, - << (static fn () => [ + new RequirementCollection(false), + IO::VERBOSITY_DEBUG, + true, + << Using PHP {$phpVersion} - > PHP is not using any php.ini file. + > Using PHP {$phpVersion} + > PHP is not using any php.ini file. - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ]; - })(); + EOF + ])(); - yield 'no requirement; verbosity=very verbose' => (static function () use ($phpVersion) { - return [ - new RequirementCollection(), - IO::VERBOSITY_VERY_VERBOSE, - true, - << (static fn () => [ + new RequirementCollection(), + IO::VERBOSITY_VERY_VERBOSE, + true, + << Using PHP {$phpVersion} - > PHP is using the following php.ini file: - /path/to/php.ini + > Using PHP {$phpVersion} + > PHP is using the following php.ini file: + /path/to/php.ini - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ]; - })(); + EOF + ])(); foreach ($remainingVerbosities as $label => $verbosity) { - yield 'no requirements; '.$label => (static function () use ($verbosity) { - return [ - new RequirementCollection(), - $verbosity, - true, - '', - ]; - })(); + yield 'no requirements; '.$label => (static fn () => [ + new RequirementCollection(), + $verbosity, + true, + '', + ])(); } yield 'requirements; check passes; verbosity=debug' => (static function () use ($phpVersion) { diff --git a/requirement-checker/tests/RequirementTest.php b/requirement-checker/tests/RequirementTest.php index 4de0e0a1a..594cbda85 100644 --- a/requirement-checker/tests/RequirementTest.php +++ b/requirement-checker/tests/RequirementTest.php @@ -57,7 +57,7 @@ public function __invoke(): bool $requirement->isFulfilled(); self::fail('Expected exception to be thrown.'); - } catch (Error $error) { + } catch (Error) { self::assertTrue(true); } } From e34e5157af1d9f423591b40444bfed15c71d0ace Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Tue, 21 Nov 2023 23:07:12 +0100 Subject: [PATCH 05/12] fix --- src/Phar/PharMeta.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index a998888d6..29e7e5d8e 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -22,8 +22,8 @@ use SplFileInfo; use Symfony\Component\Filesystem\Path; use UnexpectedValueException; +use function json_decode; use function ksort; -use function Safe\json_decode; use function Safe\json_encode; use function Safe\realpath; use function sprintf; From 2139fe9760553535f442b65cf7847d93493a946d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:27:13 +0100 Subject: [PATCH 06/12] fix --- src/Box.php | 6 +++--- src/functions.php | 5 +++-- tests/Benchmark/BenchResultReaderTest.php | 6 +++--- tests/Benchmark/CompileBench.php | 2 +- 4 files changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Box.php b/src/Box.php index 39d3fb747..860274d85 100644 --- a/src/Box.php +++ b/src/Box.php @@ -463,12 +463,12 @@ private function processContents(array $files): array // Keep the fully qualified call here since this function may be executed without the right autoloading // mechanism - \KevinGH\Box\register_aliases(); + register_aliases(); if ($enableParallelization) { - \KevinGH\Box\register_error_handler(); + register_error_handler(); } - $contents = \Fidry\FileSystem\FS::getFileContents($file); + $contents = FS::getFileContents($file); $local = $mapFile($file); diff --git a/src/functions.php b/src/functions.php index 1ff33245f..f47a46b85 100644 --- a/src/functions.php +++ b/src/functions.php @@ -14,6 +14,7 @@ namespace KevinGH\Box; +use Isolated\Symfony\Component\Finder\Finder; use Composer\InstalledVersions; use ErrorException; use Phar; @@ -160,8 +161,8 @@ function format_time(float $secs): string function register_aliases(): void { // Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file. - if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) { - class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class); + if (false === class_exists(Finder::class)) { + class_alias(\Symfony\Component\Finder\Finder::class, Finder::class); } } diff --git a/tests/Benchmark/BenchResultReaderTest.php b/tests/Benchmark/BenchResultReaderTest.php index 7ef718330..6117a5ab5 100644 --- a/tests/Benchmark/BenchResultReaderTest.php +++ b/tests/Benchmark/BenchResultReaderTest.php @@ -220,9 +220,9 @@ public static function xmlProvider(): iterable yield [ $xml, [ - 'no compactors' => 2638316.8, - 'with compactors; no parallel processing' => 2612822.4, - 'with compactors; parallel processing' => 2967538.1, + 'no compactors' => 2_638_316.8, + 'with compactors; no parallel processing' => 2_612_822.4, + 'with compactors; parallel processing' => 2_967_538.1, ], ]; } diff --git a/tests/Benchmark/CompileBench.php b/tests/Benchmark/CompileBench.php index 589bce627..865fd8871 100644 --- a/tests/Benchmark/CompileBench.php +++ b/tests/Benchmark/CompileBench.php @@ -28,7 +28,7 @@ use Symfony\Component\Console\Output\NullOutput; use function Safe\chdir; -final class CompileBench +final readonly class CompileBench { private const WITHOUT_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/without-compactors'; private const WITH_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/with-compactors'; From 706bcb60947d5c222d703d969c1a4cf241223a3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:28:41 +0100 Subject: [PATCH 07/12] fix: --- requirement-checker/tests/CheckerTest.php | 102 ++++++++++++---------- 1 file changed, 55 insertions(+), 47 deletions(-) diff --git a/requirement-checker/tests/CheckerTest.php b/requirement-checker/tests/CheckerTest.php index 491637e56..0bad0cce2 100644 --- a/requirement-checker/tests/CheckerTest.php +++ b/requirement-checker/tests/CheckerTest.php @@ -64,81 +64,89 @@ public static function provideRequirements(): iterable $phpVersion = PHP_VERSION; $remainingVerbosities = ['verbosity=verbose' => IO::VERBOSITY_VERBOSE, 'verbosity=normal' => IO::VERBOSITY_NORMAL, 'verbosity=quiet' => IO::VERBOSITY_QUIET]; - yield 'no requirement; verbosity=debug' => (static fn () => [ - new RequirementCollection(), - IO::VERBOSITY_DEBUG, - true, - << (static function () use ($phpVersion) { + return [ + new RequirementCollection(), + IO::VERBOSITY_DEBUG, + true, + << Using PHP {$phpVersion} - > PHP is using the following php.ini file: - /path/to/php.ini + > Using PHP {$phpVersion} + > PHP is using the following php.ini file: + /path/to/php.ini - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ])(); + EOF + ]; + })(); - yield 'no requirement + no ini path; verbosity=debug' => (static fn () => [ - new RequirementCollection(false), - IO::VERBOSITY_DEBUG, - true, - << (static function () use ($phpVersion) { + return [ + new RequirementCollection(false), + IO::VERBOSITY_DEBUG, + true, + << Using PHP {$phpVersion} - > PHP is not using any php.ini file. + > Using PHP {$phpVersion} + > PHP is not using any php.ini file. - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ])(); + EOF + ]; + })(); - yield 'no requirement; verbosity=very verbose' => (static fn () => [ - new RequirementCollection(), - IO::VERBOSITY_VERY_VERBOSE, - true, - << (static function () use ($phpVersion) { + return [ + new RequirementCollection(), + IO::VERBOSITY_VERY_VERBOSE, + true, + << Using PHP {$phpVersion} - > PHP is using the following php.ini file: - /path/to/php.ini + > Using PHP {$phpVersion} + > PHP is using the following php.ini file: + /path/to/php.ini - > No requirements found. + > No requirements found. - [OK] Your system is ready to run the application. + [OK] Your system is ready to run the application. - EOF - ])(); + EOF + ]; + })(); foreach ($remainingVerbosities as $label => $verbosity) { - yield 'no requirements; '.$label => (static fn () => [ - new RequirementCollection(), - $verbosity, - true, - '', - ])(); + yield 'no requirements; '.$label => (static function () use ($verbosity) { + return [ + new RequirementCollection(), + $verbosity, + true, + '', + ]; + })(); } yield 'requirements; check passes; verbosity=debug' => (static function () use ($phpVersion) { From fd8613804a138249c61da2348b227d02c1d079a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:37:44 +0100 Subject: [PATCH 08/12] reset --- requirement-checker/src/Checker.php | 2 +- requirement-checker/tests/RequirementTest.php | 2 +- src/Annotation/DocblockAnnotationParser.php | 6 +- src/Box.php | 6 +- src/Compactor/Compactors.php | 2 +- src/Compactor/FileExtensionCompactor.php | 2 +- src/Compactor/Php.php | 2 +- src/Compactor/PhpScoper.php | 2 +- src/Compactor/Placeholder.php | 2 +- src/Composer/CompilerPsrLogger.php | 2 +- src/Composer/ComposerFile.php | 4 +- src/Composer/ComposerFiles.php | 8 +-- src/Composer/ComposerOrchestrator.php | 6 +- src/Composer/ComposerProcessFactory.php | 6 +- src/Configuration/Configuration.php | 70 +++++++++---------- src/Configuration/ConfigurationLoader.php | 4 +- src/Configuration/ExportableConfiguration.php | 70 +++++++++---------- src/Console/Application.php | 43 +++++------- src/Console/Command/Compile.php | 2 +- src/Console/Logger/CompilerLogger.php | 4 +- src/Console/PharInfoRenderer.php | 3 +- src/Console/Php/PhpSettingsHandler.php | 4 +- src/DockerFileGenerator.php | 4 +- src/Json/Json.php | 2 +- src/Json/JsonValidationException.php | 4 +- src/MapFile.php | 2 +- src/Phar/Differ/ChecksumDiffer.php | 2 +- src/Phar/Differ/ProcessCommandBasedDiffer.php | 2 +- src/Phar/PharInfo.php | 10 +-- src/Phar/PharMeta.php | 25 ++++--- src/PhpScoper/ExcludedFilesScoper.php | 4 +- src/PhpScoper/SerializablePatcher.php | 2 +- src/PhpScoper/SerializableScoper.php | 2 +- .../DecodedComposerJson.php | 4 +- .../DecodedComposerLock.php | 4 +- src/RequirementChecker/PackageInfo.php | 4 +- src/RequirementChecker/RequiredItem.php | 4 +- src/RequirementChecker/Requirement.php | 12 ++-- src/functions.php | 5 +- tests/Benchmark/BenchResultReaderTest.php | 6 +- tests/Benchmark/CompileBench.php | 2 +- tests/Console/Command/ExtractTest.php | 10 +-- tests/Phar/PharMetaTest.php | 34 ++++----- .../DecodedComposerJsonTest.php | 2 +- .../DecodedComposerLockTest.php | 2 +- 45 files changed, 194 insertions(+), 206 deletions(-) diff --git a/requirement-checker/src/Checker.php b/requirement-checker/src/Checker.php index 50de78732..91c0dc7b1 100644 --- a/requirement-checker/src/Checker.php +++ b/requirement-checker/src/Checker.php @@ -170,7 +170,7 @@ private static function createCondition($type, $condition): IsFulfilled throw new InvalidArgumentException( sprintf( 'Unknown requirement type "%s".', - $type + $type, ), ); } diff --git a/requirement-checker/tests/RequirementTest.php b/requirement-checker/tests/RequirementTest.php index 594cbda85..4de0e0a1a 100644 --- a/requirement-checker/tests/RequirementTest.php +++ b/requirement-checker/tests/RequirementTest.php @@ -57,7 +57,7 @@ public function __invoke(): bool $requirement->isFulfilled(); self::fail('Expected exception to be thrown.'); - } catch (Error) { + } catch (Error $error) { self::assertTrue(true); } } diff --git a/src/Annotation/DocblockAnnotationParser.php b/src/Annotation/DocblockAnnotationParser.php index bb12a6ed6..b53fb1cce 100644 --- a/src/Annotation/DocblockAnnotationParser.php +++ b/src/Annotation/DocblockAnnotationParser.php @@ -33,14 +33,14 @@ final class DocblockAnnotationParser /** * @var array */ - private readonly array $ignoredAnnotationsAsKeys; + private array $ignoredAnnotationsAsKeys; /** * @param string[] $ignoredAnnotations */ public function __construct( - private readonly DocBlockFactoryInterface $factory, - private readonly Formatter $tagsFormatter, + private DocBlockFactoryInterface $factory, + private Formatter $tagsFormatter, array $ignoredAnnotations, ) { $this->ignoredAnnotationsAsKeys = array_flip($ignoredAnnotations); diff --git a/src/Box.php b/src/Box.php index 860274d85..39d3fb747 100644 --- a/src/Box.php +++ b/src/Box.php @@ -463,12 +463,12 @@ private function processContents(array $files): array // Keep the fully qualified call here since this function may be executed without the right autoloading // mechanism - register_aliases(); + \KevinGH\Box\register_aliases(); if ($enableParallelization) { - register_error_handler(); + \KevinGH\Box\register_error_handler(); } - $contents = FS::getFileContents($file); + $contents = \Fidry\FileSystem\FS::getFileContents($file); $local = $mapFile($file); diff --git a/src/Compactor/Compactors.php b/src/Compactor/Compactors.php index 9a58f0011..f96bc2e60 100644 --- a/src/Compactor/Compactors.php +++ b/src/Compactor/Compactors.php @@ -28,7 +28,7 @@ final class Compactors implements Compactor, Countable /** * @var Compactor[] */ - private readonly array $compactors; + private array $compactors; private ?PhpScoper $scoperCompactor = null; diff --git a/src/Compactor/FileExtensionCompactor.php b/src/Compactor/FileExtensionCompactor.php index 15fdce28c..4c62dbb8d 100644 --- a/src/Compactor/FileExtensionCompactor.php +++ b/src/Compactor/FileExtensionCompactor.php @@ -29,7 +29,7 @@ abstract class FileExtensionCompactor extends BaseCompactor /** * @var string[] */ - private readonly array $extensions; + private array $extensions; /** * @param string[] $extensions the list of supported file extensions diff --git a/src/Compactor/Php.php b/src/Compactor/Php.php index 6d8d0c34e..6f0d1e077 100644 --- a/src/Compactor/Php.php +++ b/src/Compactor/Php.php @@ -63,7 +63,7 @@ public static function create(array $ignoredAnnotations): self } public function __construct( - private readonly ?DocblockAnnotationParser $annotationParser, + private ?DocblockAnnotationParser $annotationParser, array $extensions = ['php'], ) { parent::__construct($extensions); diff --git a/src/Compactor/PhpScoper.php b/src/Compactor/PhpScoper.php index bd6e2f09d..a2b410e5f 100644 --- a/src/Compactor/PhpScoper.php +++ b/src/Compactor/PhpScoper.php @@ -20,7 +20,7 @@ /** * @private */ -final readonly class PhpScoper implements Compactor +final class PhpScoper implements Compactor { public function __construct(private Scoper $scoper) { diff --git a/src/Compactor/Placeholder.php b/src/Compactor/Placeholder.php index 91b0f3f4b..66f66835e 100644 --- a/src/Compactor/Placeholder.php +++ b/src/Compactor/Placeholder.php @@ -23,7 +23,7 @@ final class Placeholder implements Compactor /** * @var scalar[] */ - private readonly array $placeholders; + private array $placeholders; /** * @param scalar[] $placeholders diff --git a/src/Composer/CompilerPsrLogger.php b/src/Composer/CompilerPsrLogger.php index 8f2ede149..fdd52fdca 100644 --- a/src/Composer/CompilerPsrLogger.php +++ b/src/Composer/CompilerPsrLogger.php @@ -24,7 +24,7 @@ final class CompilerPsrLogger extends AbstractLogger { public function __construct( - private readonly CompilerLogger $decoratedLogger, + private CompilerLogger $decoratedLogger, ) { } diff --git a/src/Composer/ComposerFile.php b/src/Composer/ComposerFile.php index dc8a96cea..1d362361b 100644 --- a/src/Composer/ComposerFile.php +++ b/src/Composer/ComposerFile.php @@ -18,8 +18,8 @@ final class ComposerFile { - private readonly ?string $path; - private readonly array $contents; + private ?string $path; + private array $contents; public static function createEmpty(): self { diff --git a/src/Composer/ComposerFiles.php b/src/Composer/ComposerFiles.php index 9a239043d..79a36ab14 100644 --- a/src/Composer/ComposerFiles.php +++ b/src/Composer/ComposerFiles.php @@ -18,7 +18,7 @@ use function array_map; use function array_values; -final readonly class ComposerFiles +final class ComposerFiles { public static function createEmpty(): self { @@ -30,9 +30,9 @@ public static function createEmpty(): self } public function __construct( - private ComposerFile $composerJson, - private ComposerFile $composerLock, - private ComposerFile $installedJson, + private readonly ComposerFile $composerJson, + private readonly ComposerFile $composerLock, + private readonly ComposerFile $installedJson, ) { } diff --git a/src/Composer/ComposerOrchestrator.php b/src/Composer/ComposerOrchestrator.php index 91f6c40ea..02c7f74ed 100644 --- a/src/Composer/ComposerOrchestrator.php +++ b/src/Composer/ComposerOrchestrator.php @@ -48,9 +48,9 @@ public static function create(): self } public function __construct( - private readonly ComposerProcessFactory $processFactory, - private readonly LoggerInterface $logger, - private readonly FileSystem $fileSystem, + private ComposerProcessFactory $processFactory, + private LoggerInterface $logger, + private FileSystem $fileSystem, ) { } diff --git a/src/Composer/ComposerProcessFactory.php b/src/Composer/ComposerProcessFactory.php index 16f8891cc..6584ce950 100644 --- a/src/Composer/ComposerProcessFactory.php +++ b/src/Composer/ComposerProcessFactory.php @@ -49,10 +49,10 @@ public static function create( * @param Closure():string $composerExecutableFactory */ public function __construct( - private readonly Closure $composerExecutableFactory, + private Closure $composerExecutableFactory, private ?string $verbosity, - private readonly bool $ansi, - private readonly array $defaultEnvironmentVariables, + private bool $ansi, + private array $defaultEnvironmentVariables, ) { } diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index b15dd6ed2..ddc5b051c 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -209,8 +209,8 @@ final class Configuration private const STUB_KEY = 'stub'; private const TIMESTAMP = 'timestamp'; - private readonly ?string $mainScriptPath; - private readonly ?string $mainScriptContents; + private ?string $mainScriptPath; + private ?string $mainScriptContents; private ?string $composerBin = null; public static function create(?string $file, stdClass $raw): self @@ -418,41 +418,41 @@ public static function create(?string $file, stdClass $raw): self * @param string[] $recommendations */ private function __construct( - private readonly ?string $file, - private readonly string $alias, - private readonly string $basePath, - private readonly ComposerFile $composerJson, - private readonly ComposerFile $composerLock, - private readonly array $files, - private readonly array $binaryFiles, - private readonly bool $autodiscoveredFiles, - private readonly bool $dumpAutoload, - private readonly bool $excludeComposerFiles, - private readonly bool $excludeDevFiles, - private readonly Compactors|array $compactors, - private readonly CompressionAlgorithm $compressionAlgorithm, - private readonly int|string|null $fileMode, + private ?string $file, + private string $alias, + private string $basePath, + private ComposerFile $composerJson, + private ComposerFile $composerLock, + private array $files, + private array $binaryFiles, + private bool $autodiscoveredFiles, + private bool $dumpAutoload, + private bool $excludeComposerFiles, + private bool $excludeDevFiles, + private Compactors|array $compactors, + private CompressionAlgorithm $compressionAlgorithm, + private int|string|null $fileMode, ?string $mainScriptPath, ?string $mainScriptContents, - private readonly MapFile $fileMapper, - private readonly mixed $metadata, - private readonly string $tmpOutputPath, - private readonly string $outputPath, - private readonly ?string $privateKeyPassphrase, - private readonly ?string $privateKeyPath, - private readonly bool $promptForPrivateKey, - private readonly array $processedReplacements, - private readonly ?string $shebang, - private readonly SigningAlgorithm $signingAlgorithm, - private readonly ?string $stubBannerContents, - private readonly ?string $stubBannerPath, - private readonly ?string $stubPath, - private readonly bool $isInterceptFileFuncs, - private readonly bool $isStubGenerated, - private readonly ?DateTimeImmutable $timestamp, - private readonly bool $checkRequirements, - private readonly array $warnings, - private readonly array $recommendations, + private MapFile $fileMapper, + private mixed $metadata, + private string $tmpOutputPath, + private string $outputPath, + private ?string $privateKeyPassphrase, + private ?string $privateKeyPath, + private bool $promptForPrivateKey, + private array $processedReplacements, + private ?string $shebang, + private SigningAlgorithm $signingAlgorithm, + private ?string $stubBannerContents, + private ?string $stubBannerPath, + private ?string $stubPath, + private bool $isInterceptFileFuncs, + private bool $isStubGenerated, + private ?DateTimeImmutable $timestamp, + private bool $checkRequirements, + private array $warnings, + private array $recommendations, ) { if (null === $mainScriptPath) { Assert::null($mainScriptContents); diff --git a/src/Configuration/ConfigurationLoader.php b/src/Configuration/ConfigurationLoader.php index 6a2dabd1b..81405c65d 100644 --- a/src/Configuration/ConfigurationLoader.php +++ b/src/Configuration/ConfigurationLoader.php @@ -20,11 +20,11 @@ /** * @private */ -final readonly class ConfigurationLoader +final class ConfigurationLoader { private const SCHEMA_FILE = __DIR__.'/../../res/schema.json'; - public function __construct(private Json $json = new Json()) + public function __construct(private readonly Json $json = new Json()) { } diff --git a/src/Configuration/ExportableConfiguration.php b/src/Configuration/ExportableConfiguration.php index a4151acb6..2bc2ff595 100644 --- a/src/Configuration/ExportableConfiguration.php +++ b/src/Configuration/ExportableConfiguration.php @@ -34,7 +34,7 @@ * * @internal */ -final readonly class ExportableConfiguration +final class ExportableConfiguration { public static function create(Configuration $configuration): self { @@ -114,40 +114,40 @@ private static function createPathNormalizer(string $basePath): Closure /** @noinspection PhpPropertyOnlyWrittenInspection */ private function __construct( - private ?string $file, - private string $alias, - private string $basePath, - private ComposerFile $composerJson, - private ComposerFile $composerLock, - private array $files, - private array $binaryFiles, - private bool $autodiscoveredFiles, - private bool $dumpAutoload, - private bool $excludeComposerFiles, - private bool $excludeDevFiles, - private Compactors|array $compactors, - private string $compressionAlgorithm, - private int|string|null $fileMode, - private ?string $mainScriptPath, - private ?string $mainScriptContents, - private MapFile $fileMapper, - private mixed $metadata, - private string $tmpOutputPath, - private string $outputPath, - private ?string $privateKeyPassphrase, - private ?string $privateKeyPath, - private bool $promptForPrivateKey, - private array $processedReplacements, - private ?string $shebang, - private string $signingAlgorithm, - private ?string $stubBannerContents, - private ?string $stubBannerPath, - private ?string $stubPath, - private bool $isInterceptFileFuncs, - private bool $isStubGenerated, - private bool $checkRequirements, - private array $warnings, - private array $recommendations, + private readonly ?string $file, + private readonly string $alias, + private readonly string $basePath, + private readonly ComposerFile $composerJson, + private readonly ComposerFile $composerLock, + private readonly array $files, + private readonly array $binaryFiles, + private readonly bool $autodiscoveredFiles, + private readonly bool $dumpAutoload, + private readonly bool $excludeComposerFiles, + private readonly bool $excludeDevFiles, + private readonly Compactors|array $compactors, + private readonly string $compressionAlgorithm, + private readonly int|string|null $fileMode, + private readonly ?string $mainScriptPath, + private readonly ?string $mainScriptContents, + private readonly MapFile $fileMapper, + private readonly mixed $metadata, + private readonly string $tmpOutputPath, + private readonly string $outputPath, + private readonly ?string $privateKeyPassphrase, + private readonly ?string $privateKeyPath, + private readonly bool $promptForPrivateKey, + private readonly array $processedReplacements, + private readonly ?string $shebang, + private readonly string $signingAlgorithm, + private readonly ?string $stubBannerContents, + private readonly ?string $stubBannerPath, + private readonly ?string $stubPath, + private readonly bool $isInterceptFileFuncs, + private readonly bool $isStubGenerated, + private readonly bool $checkRequirements, + private readonly array $warnings, + private readonly array $recommendations, ) { } diff --git a/src/Console/Application.php b/src/Console/Application.php index 193959766..47d6e209b 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -15,17 +15,6 @@ namespace KevinGH\Box\Console; use Fidry\Console\Application\Application as FidryApplication; -use KevinGH\Box\Console\Command\Compile; -use KevinGH\Box\Console\Command\Composer\ComposerCheckVersion; -use KevinGH\Box\Console\Command\Composer\ComposerVendorDir; -use KevinGH\Box\Console\Command\Diff; -use KevinGH\Box\Console\Command\Extract; -use KevinGH\Box\Console\Command\GenerateDockerFile; -use KevinGH\Box\Console\Command\Info; -use KevinGH\Box\Console\Command\Namespace_; -use KevinGH\Box\Console\Command\Process; -use KevinGH\Box\Console\Command\Validate; -use KevinGH\Box\Console\Command\Verify; use function KevinGH\Box\get_box_version; use function sprintf; use function trim; @@ -35,16 +24,16 @@ */ final class Application implements FidryApplication { - private readonly string $version; - private readonly string $releaseDate; + private string $version; + private string $releaseDate; private string $header; public function __construct( - private readonly string $name = 'Box', + private string $name = 'Box', ?string $version = null, string $releaseDate = '@release-date@', - private readonly bool $autoExit = true, - private readonly bool $catchExceptions = true, + private bool $autoExit = true, + private bool $catchExceptions = true, ) { $this->version = $version ?? get_box_version(); $this->releaseDate = !str_contains($releaseDate, '@') ? $releaseDate : ''; @@ -89,17 +78,17 @@ public function getHeader(): string public function getCommands(): array { return [ - new ComposerCheckVersion(), - new ComposerVendorDir(), - new Compile($this->getHeader()), - new Diff(), - new Info(), - new Process(), - new Extract(), - new Validate(), - new Verify(), - new GenerateDockerFile(), - new Namespace_(), + new Command\Composer\ComposerCheckVersion(), + new Command\Composer\ComposerVendorDir(), + new Command\Compile($this->getHeader()), + new Command\Diff(), + new Command\Info(), + new Command\Process(), + new Command\Extract(), + new Command\Validate(), + new Command\Verify(), + new Command\GenerateDockerFile(), + new Command\Namespace_(), ]; } diff --git a/src/Console/Command/Compile.php b/src/Console/Command/Compile.php index 6e1598f4c..33d231208 100644 --- a/src/Console/Command/Compile.php +++ b/src/Console/Command/Compile.php @@ -111,7 +111,7 @@ final class Compile implements CommandAware private const DEBUG_DIR = '.box_dump'; - public function __construct(private readonly string $header) + public function __construct(private string $header) { } diff --git a/src/Console/Logger/CompilerLogger.php b/src/Console/Logger/CompilerLogger.php index 2cd3bc034..5b19775f5 100644 --- a/src/Console/Logger/CompilerLogger.php +++ b/src/Console/Logger/CompilerLogger.php @@ -22,7 +22,7 @@ /** * @internal */ -final readonly class CompilerLogger +final class CompilerLogger { public const QUESTION_MARK_PREFIX = '?'; public const STAR_PREFIX = '*'; @@ -30,7 +30,7 @@ public const MINUS_PREFIX = '-'; public const CHEVRON_PREFIX = '>'; - public function __construct(private IO $io) + public function __construct(private readonly IO $io) { } diff --git a/src/Console/PharInfoRenderer.php b/src/Console/PharInfoRenderer.php index 02dda1dd1..14559216c 100644 --- a/src/Console/PharInfoRenderer.php +++ b/src/Console/PharInfoRenderer.php @@ -35,6 +35,7 @@ use function count; use function implode; use function is_array; +use function KevinGH\Box\format_size; use function KevinGH\Box\format_size as format_size1; use function key; use function preg_match; @@ -255,7 +256,7 @@ public static function renderContentsSummary(PharInfo $pharInfo, IO $io): void sprintf( 'Contents:%s (%s)', 1 === $totalCount ? ' 1 file' : " {$totalCount} files", - format_size1( + format_size( filesize($pharInfo->getFile()), ), ), diff --git a/src/Console/Php/PhpSettingsHandler.php b/src/Console/Php/PhpSettingsHandler.php index 59120dd0f..059716b90 100644 --- a/src/Console/Php/PhpSettingsHandler.php +++ b/src/Console/Php/PhpSettingsHandler.php @@ -34,8 +34,8 @@ */ final class PhpSettingsHandler extends XdebugHandler { - private readonly LoggerInterface $logger; - private readonly bool $pharReadonly; + private LoggerInterface $logger; + private bool $pharReadonly; public function __construct(LoggerInterface $logger) { diff --git a/src/DockerFileGenerator.php b/src/DockerFileGenerator.php index 39c36b2f4..f8ae840a9 100644 --- a/src/DockerFileGenerator.php +++ b/src/DockerFileGenerator.php @@ -55,12 +55,12 @@ final class DockerFileGenerator '7.0.0' => '7-cli-alpine', ]; - private readonly string $image; + private string $image; /** * @var string[] */ - private readonly array $extensions; + private array $extensions; /** * Creates a new instance of the generator. diff --git a/src/Json/Json.php b/src/Json/Json.php index 823c0881f..a49b999fd 100644 --- a/src/Json/Json.php +++ b/src/Json/Json.php @@ -28,7 +28,7 @@ /** * @private */ -final readonly class Json +final class Json { private JsonParser $linter; diff --git a/src/Json/JsonValidationException.php b/src/Json/JsonValidationException.php index 2e6990f6a..288837755 100644 --- a/src/Json/JsonValidationException.php +++ b/src/Json/JsonValidationException.php @@ -23,8 +23,8 @@ */ final class JsonValidationException extends UnexpectedValueException { - private readonly ?string $validatedFile; - private readonly array $errors; + private ?string $validatedFile; + private array $errors; /** * @param string[] $errors diff --git a/src/MapFile.php b/src/MapFile.php index bf23c7507..2bedefd79 100644 --- a/src/MapFile.php +++ b/src/MapFile.php @@ -23,7 +23,7 @@ * * @private */ -final readonly class MapFile +final class MapFile { /** * @param string[][] $map diff --git a/src/Phar/Differ/ChecksumDiffer.php b/src/Phar/Differ/ChecksumDiffer.php index 02c59e57e..06121135d 100644 --- a/src/Phar/Differ/ChecksumDiffer.php +++ b/src/Phar/Differ/ChecksumDiffer.php @@ -21,7 +21,7 @@ use function hash; use function implode; -final readonly class ChecksumDiffer implements Differ +final class ChecksumDiffer implements Differ { public function __construct( private string $checksumAlgorithm, diff --git a/src/Phar/Differ/ProcessCommandBasedDiffer.php b/src/Phar/Differ/ProcessCommandBasedDiffer.php index ba820877b..eab2442a1 100644 --- a/src/Phar/Differ/ProcessCommandBasedDiffer.php +++ b/src/Phar/Differ/ProcessCommandBasedDiffer.php @@ -18,7 +18,7 @@ use KevinGH\Box\Phar\PharInfo; use Symfony\Component\Process\Process; -final readonly class ProcessCommandBasedDiffer implements Differ +final class ProcessCommandBasedDiffer implements Differ { public function __construct(private string $command) { diff --git a/src/Phar/PharInfo.php b/src/Phar/PharInfo.php index 2865938b9..a71723cb1 100644 --- a/src/Phar/PharInfo.php +++ b/src/Phar/PharInfo.php @@ -77,16 +77,16 @@ final class PharInfo private static array $ALGORITHMS; private static string $stubfile; - private readonly PharMeta $meta; - private readonly string $tmp; - private readonly string $file; - private readonly string $fileName; + private PharMeta $meta; + private string $tmp; + private string $file; + private string $fileName; private array $compressionCount; /** * @var array */ - private readonly array $files; + private array $files; public function __construct(string $file) { diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index 29e7e5d8e..af51a3a4b 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -22,13 +22,12 @@ use SplFileInfo; use Symfony\Component\Filesystem\Path; use UnexpectedValueException; -use function json_decode; use function ksort; +use function Safe\json_decode; use function Safe\json_encode; use function Safe\realpath; use function sprintf; use function var_export; -use const JSON_THROW_ON_ERROR; use const SORT_LOCALE_STRING; /** @@ -37,7 +36,7 @@ * * @private */ -final readonly class PharMeta +final class PharMeta { /** * @param non-empty-string|null $stub @@ -47,15 +46,15 @@ * @param array $filesMeta */ public function __construct( - public CompressionAlgorithm $compression, + public readonly CompressionAlgorithm $compression, #[ArrayShape(['hash' => 'string', 'hash_type' => 'string'])] - public ?array $signature, - public ?string $stub, - public ?string $version, - public ?string $normalizedMetadata, - public int $timestamp, - public ?string $pubKeyContent, - public array $filesMeta, + public readonly ?array $signature, + public readonly ?string $stub, + public readonly ?string $version, + public readonly ?string $normalizedMetadata, + public readonly int $timestamp, + public readonly ?string $pubKeyContent, + public readonly array $filesMeta, ) { } @@ -83,7 +82,7 @@ public static function fromPhar(Phar|PharData $phar, ?string $pubKeyContent): se public static function fromJson(string $json): self { - $decodedJson = json_decode($json, true, flags: JSON_THROW_ON_ERROR); + $decodedJson = json_decode($json, true); $filesMeta = $decodedJson['filesMeta']; @@ -114,7 +113,7 @@ public function toJson(): string 'timestamp' => $this->timestamp, 'pubKeyContent' => $this->pubKeyContent, 'filesMeta' => $this->filesMeta, - ], JSON_THROW_ON_ERROR); + ]); } /** diff --git a/src/PhpScoper/ExcludedFilesScoper.php b/src/PhpScoper/ExcludedFilesScoper.php index b99f3e69a..fd3c8f90c 100644 --- a/src/PhpScoper/ExcludedFilesScoper.php +++ b/src/PhpScoper/ExcludedFilesScoper.php @@ -21,10 +21,10 @@ final class ExcludedFilesScoper implements PhpScoperScoper { - private readonly array $excludedFilePathsAsKeys; + private array $excludedFilePathsAsKeys; public function __construct( - private readonly PhpScoperScoper $decoratedScoper, + private PhpScoperScoper $decoratedScoper, string ...$excludedFilePaths, ) { $this->excludedFilePathsAsKeys = array_flip($excludedFilePaths); diff --git a/src/PhpScoper/SerializablePatcher.php b/src/PhpScoper/SerializablePatcher.php index c436b3b61..14f51d7c0 100644 --- a/src/PhpScoper/SerializablePatcher.php +++ b/src/PhpScoper/SerializablePatcher.php @@ -22,7 +22,7 @@ /** * @var PatcherCallable = (string $filePath, string $prefix, string $contents): string */ -final readonly class SerializablePatcher implements Patcher +final class SerializablePatcher implements Patcher { public static function create(callable $patcher): self { diff --git a/src/PhpScoper/SerializableScoper.php b/src/PhpScoper/SerializableScoper.php index d9b845a0d..152c00e87 100644 --- a/src/PhpScoper/SerializableScoper.php +++ b/src/PhpScoper/SerializableScoper.php @@ -25,7 +25,7 @@ */ final class SerializableScoper implements Scoper { - private readonly PhpScoperConfiguration $scoperConfig; + private PhpScoperConfiguration $scoperConfig; private PhpScoperContainer $scoperContainer; private PhpScoperScoper $scoper; private SymbolsRegistry $symbolsRegistry; diff --git a/src/RequirementChecker/DecodedComposerJson.php b/src/RequirementChecker/DecodedComposerJson.php index 326882a9b..01e0fb953 100644 --- a/src/RequirementChecker/DecodedComposerJson.php +++ b/src/RequirementChecker/DecodedComposerJson.php @@ -19,12 +19,12 @@ /** * @private */ -final readonly class DecodedComposerJson +final class DecodedComposerJson { /** * @param array $composerJsonDecodedContents Decoded JSON contents of the `composer.json` file */ - public function __construct(private array $composerJsonDecodedContents) + public function __construct(private readonly array $composerJsonDecodedContents) { } diff --git a/src/RequirementChecker/DecodedComposerLock.php b/src/RequirementChecker/DecodedComposerLock.php index 651b64527..ba5d7f473 100644 --- a/src/RequirementChecker/DecodedComposerLock.php +++ b/src/RequirementChecker/DecodedComposerLock.php @@ -19,12 +19,12 @@ /** * @private */ -final readonly class DecodedComposerLock +final class DecodedComposerLock { /** * @param array $composerLockDecodedContents Decoded JSON contents of the `composer.lock` file */ - public function __construct(private array $composerLockDecodedContents) + public function __construct(private readonly array $composerLockDecodedContents) { } diff --git a/src/RequirementChecker/PackageInfo.php b/src/RequirementChecker/PackageInfo.php index 5f4fbf8ad..3ff05aa25 100644 --- a/src/RequirementChecker/PackageInfo.php +++ b/src/RequirementChecker/PackageInfo.php @@ -19,7 +19,7 @@ /** * @private */ -final readonly class PackageInfo +final class PackageInfo { private const EXTENSION_REGEX = '/^ext-(?.+)$/'; @@ -37,7 +37,7 @@ private const SYMFONY_POLYFILL_REGEX = '/symfony\/polyfill-(?.+)/'; - public function __construct(private array $packageInfo) + public function __construct(private readonly array $packageInfo) { } diff --git a/src/RequirementChecker/RequiredItem.php b/src/RequirementChecker/RequiredItem.php index 9036d426b..5bd38e19e 100644 --- a/src/RequirementChecker/RequiredItem.php +++ b/src/RequirementChecker/RequiredItem.php @@ -20,7 +20,7 @@ /** * @private */ -final readonly class RequiredItem +final class RequiredItem { private const POLYFILL_MAP = [ 'paragonie/sodium_compat' => 'libsodium', @@ -32,7 +32,7 @@ /** * @param array $packageInfo */ - public function __construct(private array $packageInfo) + public function __construct(private readonly array $packageInfo) { } diff --git a/src/RequirementChecker/Requirement.php b/src/RequirementChecker/Requirement.php index fe1d8e3ef..73feb9a7d 100644 --- a/src/RequirementChecker/Requirement.php +++ b/src/RequirementChecker/Requirement.php @@ -17,14 +17,14 @@ /** * @private */ -final readonly class Requirement +final class Requirement { public function __construct( - public RequirementType $type, - public string $condition, - public ?string $source, - public string $message, - public string $helpMessage, + public readonly RequirementType $type, + public readonly string $condition, + public readonly ?string $source, + public readonly string $message, + public readonly string $helpMessage, ) { } diff --git a/src/functions.php b/src/functions.php index f47a46b85..1ff33245f 100644 --- a/src/functions.php +++ b/src/functions.php @@ -14,7 +14,6 @@ namespace KevinGH\Box; -use Isolated\Symfony\Component\Finder\Finder; use Composer\InstalledVersions; use ErrorException; use Phar; @@ -161,8 +160,8 @@ function format_time(float $secs): string function register_aliases(): void { // Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file. - if (false === class_exists(Finder::class)) { - class_alias(\Symfony\Component\Finder\Finder::class, Finder::class); + if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) { + class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class); } } diff --git a/tests/Benchmark/BenchResultReaderTest.php b/tests/Benchmark/BenchResultReaderTest.php index 6117a5ab5..7ef718330 100644 --- a/tests/Benchmark/BenchResultReaderTest.php +++ b/tests/Benchmark/BenchResultReaderTest.php @@ -220,9 +220,9 @@ public static function xmlProvider(): iterable yield [ $xml, [ - 'no compactors' => 2_638_316.8, - 'with compactors; no parallel processing' => 2_612_822.4, - 'with compactors; parallel processing' => 2_967_538.1, + 'no compactors' => 2638316.8, + 'with compactors; no parallel processing' => 2612822.4, + 'with compactors; parallel processing' => 2967538.1, ], ]; } diff --git a/tests/Benchmark/CompileBench.php b/tests/Benchmark/CompileBench.php index 865fd8871..589bce627 100644 --- a/tests/Benchmark/CompileBench.php +++ b/tests/Benchmark/CompileBench.php @@ -28,7 +28,7 @@ use Symfony\Component\Console\Output\NullOutput; use function Safe\chdir; -final readonly class CompileBench +final class CompileBench { private const WITHOUT_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/without-compactors'; private const WITH_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/with-compactors'; diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index b86d3c659..cd7aa24af 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -84,7 +84,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1_559_806_605, + 1559806605, null, [ '.hidden' => [ @@ -131,7 +131,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1_559_807_994, + 1559807994, null, [ '.hidden' => [ @@ -160,7 +160,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1_374_531_272, + 1374531272, null, [ 'index.php' => [ @@ -189,7 +189,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1_374_531_313, + 1374531313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -324,7 +324,7 @@ public function test_it_cannot_extract_an_invalid_phar(string $pharPath): void ); self::assertSame(ExitCode::FAILURE, $this->commandTester->getStatusCode()); - } catch (InvalidPhar) { + } catch (InvalidPhar $exception) { // Continue } diff --git a/tests/Phar/PharMetaTest.php b/tests/Phar/PharMetaTest.php index 8396776c8..7dde21c9a 100644 --- a/tests/Phar/PharMetaTest.php +++ b/tests/Phar/PharMetaTest.php @@ -47,7 +47,7 @@ public static function pharMetaProvider(): iterable null, null, null, - 1_509_920_675, + 1509920675, null, [], ), @@ -64,7 +64,7 @@ public static function pharMetaProvider(): iterable 'action' => 'sayHello', ) EOL, - 1_509_920_675, + 1509920675, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -123,7 +123,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1_680_285_013, + 1680285013, null, [ 'sample.php' => [ @@ -146,7 +146,7 @@ public static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1_509_920_675, + 1509920675, null, [ 'foo.php' => [ @@ -169,7 +169,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1_680_680_933, + 1680680933, null, [ 'sample.php' => [ @@ -197,7 +197,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1_680_469_485, + 1680469485, null, [ 'sample.php' => [ @@ -222,7 +222,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1_680_469_504, + 1680469504, null, [ 'sample.php' => [ @@ -246,7 +246,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1_374_531_272, + 1374531272, null, [ 'index.php' => [ @@ -269,7 +269,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1_374_531_313, + 1374531313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -298,7 +298,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', "'Hello world!'", - 1_680_366_918, + 1680366918, null, [ 'sample.php' => [ @@ -321,7 +321,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', '-19.8', - 1_680_366_947, + 1680366947, null, [ 'sample.php' => [ @@ -348,7 +348,7 @@ public static function pharProvider(): iterable 'action' => 'sayHello', ) EOL, - 1_680_367_053, + 1680367053, null, [ 'sample.php' => [ @@ -368,7 +368,7 @@ public static function pharProvider(): iterable null, null, null, - 1_680_284_754, + 1680284754, null, [ 'sample.txt' => [ @@ -389,7 +389,7 @@ public static function pharProvider(): iterable null, null, null, - 1_680_284_663, + 1680284663, null, [ 'sample.txt' => [ @@ -411,7 +411,7 @@ public static function pharProvider(): iterable null, null, null, - 1_680_284_660, + 1680284660, null, [ 'sample.txt' => [ @@ -433,7 +433,7 @@ public static function pharProvider(): iterable null, null, null, - 1_680_284_663, + 1680284663, null, [ 'sample.txt' => [ @@ -457,7 +457,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1_680_645_848, + 1680645848, null, [ '.hidden-dir/.hidden-file' => [ diff --git a/tests/RequirementChecker/DecodedComposerJsonTest.php b/tests/RequirementChecker/DecodedComposerJsonTest.php index 375d2b092..af63d04ed 100644 --- a/tests/RequirementChecker/DecodedComposerJsonTest.php +++ b/tests/RequirementChecker/DecodedComposerJsonTest.php @@ -15,7 +15,7 @@ namespace KevinGH\Box\RequirementChecker; use PHPUnit\Framework\TestCase; -use function Safe\json_decode; +use function json_decode; /** * @covers \KevinGH\Box\RequirementChecker\DecodedComposerJson diff --git a/tests/RequirementChecker/DecodedComposerLockTest.php b/tests/RequirementChecker/DecodedComposerLockTest.php index 7a4b5f759..1a8658d57 100644 --- a/tests/RequirementChecker/DecodedComposerLockTest.php +++ b/tests/RequirementChecker/DecodedComposerLockTest.php @@ -15,7 +15,7 @@ namespace KevinGH\Box\RequirementChecker; use PHPUnit\Framework\TestCase; -use function Safe\json_decode; +use function json_decode; /** * @covers \KevinGH\Box\RequirementChecker\DecodedComposerLock From ab5f557028d83d88fba7e6956e8f90d642169d98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:42:05 +0100 Subject: [PATCH 09/12] fix config --- rector.php | 1 + src/Console/PharInfoRenderer.php | 3 +-- src/functions.php | 6 ++++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/rector.php b/rector.php index 210dffafb..bfaf4a6a2 100644 --- a/rector.php +++ b/rector.php @@ -24,6 +24,7 @@ $rectorConfig->skip([ \Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector::class, + \Rector\Php73\Rector\FuncCall\JsonThrowOnErrorRector::class, \Rector\Php55\Rector\String_\StringClassNameToClassConstantRector::class => [ __DIR__.'/src/Configuration/Configuration.php', ], diff --git a/src/Console/PharInfoRenderer.php b/src/Console/PharInfoRenderer.php index 14559216c..547781632 100644 --- a/src/Console/PharInfoRenderer.php +++ b/src/Console/PharInfoRenderer.php @@ -36,7 +36,6 @@ use function implode; use function is_array; use function KevinGH\Box\format_size; -use function KevinGH\Box\format_size as format_size1; use function key; use function preg_match; use function round; @@ -307,7 +306,7 @@ public static function renderContent( ? $splFileInfo->getFilename() : $splFileInfo->getRelativePathname(), $compressionLine, - format_size1($compressionSize), + format_size($compressionSize), ), $depth, $indent, diff --git a/src/functions.php b/src/functions.php index 1ff33245f..b2ec30a4e 100644 --- a/src/functions.php +++ b/src/functions.php @@ -16,8 +16,10 @@ use Composer\InstalledVersions; use ErrorException; +use Isolated\Symfony\Component\Finder\Finder as IsolatedFinder; use Phar; use Symfony\Component\Console\Helper\Helper; +use Symfony\Component\Finder\Finder as SymfonyFinder; use Webmozart\Assert\Assert; use function bin2hex; use function class_alias; @@ -160,8 +162,8 @@ function format_time(float $secs): string function register_aliases(): void { // Exposes the finder used by PHP-Scoper PHAR to allow its usage in the configuration file. - if (false === class_exists(\Isolated\Symfony\Component\Finder\Finder::class)) { - class_alias(\Symfony\Component\Finder\Finder::class, \Isolated\Symfony\Component\Finder\Finder::class); + if (false === class_exists(IsolatedFinder::class)) { + class_alias(SymfonyFinder::class, IsolatedFinder::class); } } From 896dd54497b018b17a739b04b86a6f691a1cb896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:46:26 +0100 Subject: [PATCH 10/12] fix config --- requirement-checker/rector-src.php | 15 ++++++--------- requirement-checker/rector-tests.php | 18 ++++++++++-------- requirement-checker/rector.php | 17 +++++++++++++++++ 3 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 requirement-checker/rector.php diff --git a/requirement-checker/rector-src.php b/requirement-checker/rector-src.php index ddf482591..ed8d99de4 100644 --- a/requirement-checker/rector-src.php +++ b/requirement-checker/rector-src.php @@ -6,20 +6,17 @@ use Rector\Set\ValueObject\DowngradeLevelSetList; use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { +$applyCommonConfig = require __DIR__.'/rector.php'; + +return static function (RectorConfig $rectorConfig) use ($applyCommonConfig): void { + $applyCommonConfig($rectorConfig); + $rectorConfig->paths([ __DIR__ . '/src', ]); - $rectorConfig->autoloadPaths([ - __DIR__ . '/vendor/autoload.php', - __DIR__ . '/../vendor-bin/rector/vendor/autoload.php', - ]); - - $rectorConfig->importNames(); - $rectorConfig->sets([ - // TODO + LevelSetList::UP_TO_PHP_72, // DowngradeLevelSetList::DOWN_TO_PHP_72, ]); }; diff --git a/requirement-checker/rector-tests.php b/requirement-checker/rector-tests.php index adda3dbce..022c82102 100644 --- a/requirement-checker/rector-tests.php +++ b/requirement-checker/rector-tests.php @@ -3,21 +3,23 @@ declare(strict_types=1); use Rector\Config\RectorConfig; +use Rector\Php74\Rector\Closure\ClosureToArrowFunctionRector; use Rector\Set\ValueObject\LevelSetList; -return static function (RectorConfig $rectorConfig): void { +$applyCommonConfig = require __DIR__.'/rector.php'; + +return static function (RectorConfig $rectorConfig) use ($applyCommonConfig): void { + $applyCommonConfig($rectorConfig); + $rectorConfig->paths([ __DIR__ . '/tests', ]); - $rectorConfig->autoloadPaths([ - __DIR__ . '/vendor/autoload.php', - __DIR__ . '/../vendor-bin/rector/vendor/autoload.php', - ]); - - $rectorConfig->importNames(); - $rectorConfig->sets([ LevelSetList::UP_TO_PHP_82, ]); + + $rectorConfig->skip([ + ClosureToArrowFunctionRector::class + ]); }; diff --git a/requirement-checker/rector.php b/requirement-checker/rector.php new file mode 100644 index 000000000..55b3259b4 --- /dev/null +++ b/requirement-checker/rector.php @@ -0,0 +1,17 @@ +autoloadPaths([ + __DIR__ . '/vendor/autoload.php', + __DIR__ . '/../vendor-bin/rector/vendor/autoload.php', + ]); + + $rectorConfig->importNames(); +}; From 6a19a90ef1183d8a8f7ab16c54df445b3584b68f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:47:29 +0100 Subject: [PATCH 11/12] apply rector --- .../src/RequirementCollection.php | 4 +- requirement-checker/tests/RequirementTest.php | 2 +- src/Annotation/DocblockAnnotationParser.php | 6 +- src/Box.php | 6 +- src/Compactor/Compactors.php | 2 +- src/Compactor/FileExtensionCompactor.php | 2 +- src/Compactor/Php.php | 2 +- src/Compactor/PhpScoper.php | 2 +- src/Compactor/Placeholder.php | 2 +- src/Composer/CompilerPsrLogger.php | 2 +- src/Composer/ComposerFile.php | 4 +- src/Composer/ComposerFiles.php | 8 +-- src/Composer/ComposerOrchestrator.php | 6 +- src/Composer/ComposerProcessFactory.php | 6 +- src/Configuration/Configuration.php | 70 +++++++++---------- src/Configuration/ConfigurationLoader.php | 4 +- src/Configuration/ExportableConfiguration.php | 70 +++++++++---------- src/Console/Application.php | 43 +++++++----- src/Console/Command/Compile.php | 2 +- src/Console/Logger/CompilerLogger.php | 4 +- src/Console/Php/PhpSettingsHandler.php | 4 +- src/DockerFileGenerator.php | 4 +- src/Json/Json.php | 2 +- src/Json/JsonValidationException.php | 4 +- src/MapFile.php | 2 +- src/Phar/Differ/ChecksumDiffer.php | 2 +- src/Phar/Differ/ProcessCommandBasedDiffer.php | 2 +- src/Phar/PharInfo.php | 10 +-- src/Phar/PharMeta.php | 18 ++--- src/PhpScoper/ExcludedFilesScoper.php | 4 +- src/PhpScoper/SerializablePatcher.php | 2 +- src/PhpScoper/SerializableScoper.php | 2 +- .../DecodedComposerJson.php | 4 +- .../DecodedComposerLock.php | 4 +- src/RequirementChecker/PackageInfo.php | 4 +- src/RequirementChecker/RequiredItem.php | 4 +- src/RequirementChecker/Requirement.php | 12 ++-- tests/Benchmark/BenchResultReaderTest.php | 6 +- tests/Benchmark/CompileBench.php | 2 +- tests/Console/Command/ExtractTest.php | 10 +-- tests/Phar/PharMetaTest.php | 34 ++++----- 41 files changed, 196 insertions(+), 187 deletions(-) diff --git a/requirement-checker/src/RequirementCollection.php b/requirement-checker/src/RequirementCollection.php index f337b09f2..6710215af 100644 --- a/requirement-checker/src/RequirementCollection.php +++ b/requirement-checker/src/RequirementCollection.php @@ -45,9 +45,7 @@ final class RequirementCollection implements IteratorAggregate, Countable */ public function __construct($phpIniPath = null) { - $this->phpIniPath = null === $phpIniPath - ? get_cfg_var('cfg_file_path') - : $phpIniPath; + $this->phpIniPath = $phpIniPath ?? get_cfg_var('cfg_file_path'); } /** diff --git a/requirement-checker/tests/RequirementTest.php b/requirement-checker/tests/RequirementTest.php index 4de0e0a1a..594cbda85 100644 --- a/requirement-checker/tests/RequirementTest.php +++ b/requirement-checker/tests/RequirementTest.php @@ -57,7 +57,7 @@ public function __invoke(): bool $requirement->isFulfilled(); self::fail('Expected exception to be thrown.'); - } catch (Error $error) { + } catch (Error) { self::assertTrue(true); } } diff --git a/src/Annotation/DocblockAnnotationParser.php b/src/Annotation/DocblockAnnotationParser.php index b53fb1cce..bb12a6ed6 100644 --- a/src/Annotation/DocblockAnnotationParser.php +++ b/src/Annotation/DocblockAnnotationParser.php @@ -33,14 +33,14 @@ final class DocblockAnnotationParser /** * @var array */ - private array $ignoredAnnotationsAsKeys; + private readonly array $ignoredAnnotationsAsKeys; /** * @param string[] $ignoredAnnotations */ public function __construct( - private DocBlockFactoryInterface $factory, - private Formatter $tagsFormatter, + private readonly DocBlockFactoryInterface $factory, + private readonly Formatter $tagsFormatter, array $ignoredAnnotations, ) { $this->ignoredAnnotationsAsKeys = array_flip($ignoredAnnotations); diff --git a/src/Box.php b/src/Box.php index 39d3fb747..860274d85 100644 --- a/src/Box.php +++ b/src/Box.php @@ -463,12 +463,12 @@ private function processContents(array $files): array // Keep the fully qualified call here since this function may be executed without the right autoloading // mechanism - \KevinGH\Box\register_aliases(); + register_aliases(); if ($enableParallelization) { - \KevinGH\Box\register_error_handler(); + register_error_handler(); } - $contents = \Fidry\FileSystem\FS::getFileContents($file); + $contents = FS::getFileContents($file); $local = $mapFile($file); diff --git a/src/Compactor/Compactors.php b/src/Compactor/Compactors.php index f96bc2e60..9a58f0011 100644 --- a/src/Compactor/Compactors.php +++ b/src/Compactor/Compactors.php @@ -28,7 +28,7 @@ final class Compactors implements Compactor, Countable /** * @var Compactor[] */ - private array $compactors; + private readonly array $compactors; private ?PhpScoper $scoperCompactor = null; diff --git a/src/Compactor/FileExtensionCompactor.php b/src/Compactor/FileExtensionCompactor.php index 4c62dbb8d..15fdce28c 100644 --- a/src/Compactor/FileExtensionCompactor.php +++ b/src/Compactor/FileExtensionCompactor.php @@ -29,7 +29,7 @@ abstract class FileExtensionCompactor extends BaseCompactor /** * @var string[] */ - private array $extensions; + private readonly array $extensions; /** * @param string[] $extensions the list of supported file extensions diff --git a/src/Compactor/Php.php b/src/Compactor/Php.php index 6f0d1e077..6d8d0c34e 100644 --- a/src/Compactor/Php.php +++ b/src/Compactor/Php.php @@ -63,7 +63,7 @@ public static function create(array $ignoredAnnotations): self } public function __construct( - private ?DocblockAnnotationParser $annotationParser, + private readonly ?DocblockAnnotationParser $annotationParser, array $extensions = ['php'], ) { parent::__construct($extensions); diff --git a/src/Compactor/PhpScoper.php b/src/Compactor/PhpScoper.php index a2b410e5f..bd6e2f09d 100644 --- a/src/Compactor/PhpScoper.php +++ b/src/Compactor/PhpScoper.php @@ -20,7 +20,7 @@ /** * @private */ -final class PhpScoper implements Compactor +final readonly class PhpScoper implements Compactor { public function __construct(private Scoper $scoper) { diff --git a/src/Compactor/Placeholder.php b/src/Compactor/Placeholder.php index 66f66835e..91b0f3f4b 100644 --- a/src/Compactor/Placeholder.php +++ b/src/Compactor/Placeholder.php @@ -23,7 +23,7 @@ final class Placeholder implements Compactor /** * @var scalar[] */ - private array $placeholders; + private readonly array $placeholders; /** * @param scalar[] $placeholders diff --git a/src/Composer/CompilerPsrLogger.php b/src/Composer/CompilerPsrLogger.php index fdd52fdca..8f2ede149 100644 --- a/src/Composer/CompilerPsrLogger.php +++ b/src/Composer/CompilerPsrLogger.php @@ -24,7 +24,7 @@ final class CompilerPsrLogger extends AbstractLogger { public function __construct( - private CompilerLogger $decoratedLogger, + private readonly CompilerLogger $decoratedLogger, ) { } diff --git a/src/Composer/ComposerFile.php b/src/Composer/ComposerFile.php index 1d362361b..dc8a96cea 100644 --- a/src/Composer/ComposerFile.php +++ b/src/Composer/ComposerFile.php @@ -18,8 +18,8 @@ final class ComposerFile { - private ?string $path; - private array $contents; + private readonly ?string $path; + private readonly array $contents; public static function createEmpty(): self { diff --git a/src/Composer/ComposerFiles.php b/src/Composer/ComposerFiles.php index 79a36ab14..9a239043d 100644 --- a/src/Composer/ComposerFiles.php +++ b/src/Composer/ComposerFiles.php @@ -18,7 +18,7 @@ use function array_map; use function array_values; -final class ComposerFiles +final readonly class ComposerFiles { public static function createEmpty(): self { @@ -30,9 +30,9 @@ public static function createEmpty(): self } public function __construct( - private readonly ComposerFile $composerJson, - private readonly ComposerFile $composerLock, - private readonly ComposerFile $installedJson, + private ComposerFile $composerJson, + private ComposerFile $composerLock, + private ComposerFile $installedJson, ) { } diff --git a/src/Composer/ComposerOrchestrator.php b/src/Composer/ComposerOrchestrator.php index 02c7f74ed..91f6c40ea 100644 --- a/src/Composer/ComposerOrchestrator.php +++ b/src/Composer/ComposerOrchestrator.php @@ -48,9 +48,9 @@ public static function create(): self } public function __construct( - private ComposerProcessFactory $processFactory, - private LoggerInterface $logger, - private FileSystem $fileSystem, + private readonly ComposerProcessFactory $processFactory, + private readonly LoggerInterface $logger, + private readonly FileSystem $fileSystem, ) { } diff --git a/src/Composer/ComposerProcessFactory.php b/src/Composer/ComposerProcessFactory.php index 6584ce950..16f8891cc 100644 --- a/src/Composer/ComposerProcessFactory.php +++ b/src/Composer/ComposerProcessFactory.php @@ -49,10 +49,10 @@ public static function create( * @param Closure():string $composerExecutableFactory */ public function __construct( - private Closure $composerExecutableFactory, + private readonly Closure $composerExecutableFactory, private ?string $verbosity, - private bool $ansi, - private array $defaultEnvironmentVariables, + private readonly bool $ansi, + private readonly array $defaultEnvironmentVariables, ) { } diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index ddc5b051c..b15dd6ed2 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -209,8 +209,8 @@ final class Configuration private const STUB_KEY = 'stub'; private const TIMESTAMP = 'timestamp'; - private ?string $mainScriptPath; - private ?string $mainScriptContents; + private readonly ?string $mainScriptPath; + private readonly ?string $mainScriptContents; private ?string $composerBin = null; public static function create(?string $file, stdClass $raw): self @@ -418,41 +418,41 @@ public static function create(?string $file, stdClass $raw): self * @param string[] $recommendations */ private function __construct( - private ?string $file, - private string $alias, - private string $basePath, - private ComposerFile $composerJson, - private ComposerFile $composerLock, - private array $files, - private array $binaryFiles, - private bool $autodiscoveredFiles, - private bool $dumpAutoload, - private bool $excludeComposerFiles, - private bool $excludeDevFiles, - private Compactors|array $compactors, - private CompressionAlgorithm $compressionAlgorithm, - private int|string|null $fileMode, + private readonly ?string $file, + private readonly string $alias, + private readonly string $basePath, + private readonly ComposerFile $composerJson, + private readonly ComposerFile $composerLock, + private readonly array $files, + private readonly array $binaryFiles, + private readonly bool $autodiscoveredFiles, + private readonly bool $dumpAutoload, + private readonly bool $excludeComposerFiles, + private readonly bool $excludeDevFiles, + private readonly Compactors|array $compactors, + private readonly CompressionAlgorithm $compressionAlgorithm, + private readonly int|string|null $fileMode, ?string $mainScriptPath, ?string $mainScriptContents, - private MapFile $fileMapper, - private mixed $metadata, - private string $tmpOutputPath, - private string $outputPath, - private ?string $privateKeyPassphrase, - private ?string $privateKeyPath, - private bool $promptForPrivateKey, - private array $processedReplacements, - private ?string $shebang, - private SigningAlgorithm $signingAlgorithm, - private ?string $stubBannerContents, - private ?string $stubBannerPath, - private ?string $stubPath, - private bool $isInterceptFileFuncs, - private bool $isStubGenerated, - private ?DateTimeImmutable $timestamp, - private bool $checkRequirements, - private array $warnings, - private array $recommendations, + private readonly MapFile $fileMapper, + private readonly mixed $metadata, + private readonly string $tmpOutputPath, + private readonly string $outputPath, + private readonly ?string $privateKeyPassphrase, + private readonly ?string $privateKeyPath, + private readonly bool $promptForPrivateKey, + private readonly array $processedReplacements, + private readonly ?string $shebang, + private readonly SigningAlgorithm $signingAlgorithm, + private readonly ?string $stubBannerContents, + private readonly ?string $stubBannerPath, + private readonly ?string $stubPath, + private readonly bool $isInterceptFileFuncs, + private readonly bool $isStubGenerated, + private readonly ?DateTimeImmutable $timestamp, + private readonly bool $checkRequirements, + private readonly array $warnings, + private readonly array $recommendations, ) { if (null === $mainScriptPath) { Assert::null($mainScriptContents); diff --git a/src/Configuration/ConfigurationLoader.php b/src/Configuration/ConfigurationLoader.php index 81405c65d..6a2dabd1b 100644 --- a/src/Configuration/ConfigurationLoader.php +++ b/src/Configuration/ConfigurationLoader.php @@ -20,11 +20,11 @@ /** * @private */ -final class ConfigurationLoader +final readonly class ConfigurationLoader { private const SCHEMA_FILE = __DIR__.'/../../res/schema.json'; - public function __construct(private readonly Json $json = new Json()) + public function __construct(private Json $json = new Json()) { } diff --git a/src/Configuration/ExportableConfiguration.php b/src/Configuration/ExportableConfiguration.php index 2bc2ff595..a4151acb6 100644 --- a/src/Configuration/ExportableConfiguration.php +++ b/src/Configuration/ExportableConfiguration.php @@ -34,7 +34,7 @@ * * @internal */ -final class ExportableConfiguration +final readonly class ExportableConfiguration { public static function create(Configuration $configuration): self { @@ -114,40 +114,40 @@ private static function createPathNormalizer(string $basePath): Closure /** @noinspection PhpPropertyOnlyWrittenInspection */ private function __construct( - private readonly ?string $file, - private readonly string $alias, - private readonly string $basePath, - private readonly ComposerFile $composerJson, - private readonly ComposerFile $composerLock, - private readonly array $files, - private readonly array $binaryFiles, - private readonly bool $autodiscoveredFiles, - private readonly bool $dumpAutoload, - private readonly bool $excludeComposerFiles, - private readonly bool $excludeDevFiles, - private readonly Compactors|array $compactors, - private readonly string $compressionAlgorithm, - private readonly int|string|null $fileMode, - private readonly ?string $mainScriptPath, - private readonly ?string $mainScriptContents, - private readonly MapFile $fileMapper, - private readonly mixed $metadata, - private readonly string $tmpOutputPath, - private readonly string $outputPath, - private readonly ?string $privateKeyPassphrase, - private readonly ?string $privateKeyPath, - private readonly bool $promptForPrivateKey, - private readonly array $processedReplacements, - private readonly ?string $shebang, - private readonly string $signingAlgorithm, - private readonly ?string $stubBannerContents, - private readonly ?string $stubBannerPath, - private readonly ?string $stubPath, - private readonly bool $isInterceptFileFuncs, - private readonly bool $isStubGenerated, - private readonly bool $checkRequirements, - private readonly array $warnings, - private readonly array $recommendations, + private ?string $file, + private string $alias, + private string $basePath, + private ComposerFile $composerJson, + private ComposerFile $composerLock, + private array $files, + private array $binaryFiles, + private bool $autodiscoveredFiles, + private bool $dumpAutoload, + private bool $excludeComposerFiles, + private bool $excludeDevFiles, + private Compactors|array $compactors, + private string $compressionAlgorithm, + private int|string|null $fileMode, + private ?string $mainScriptPath, + private ?string $mainScriptContents, + private MapFile $fileMapper, + private mixed $metadata, + private string $tmpOutputPath, + private string $outputPath, + private ?string $privateKeyPassphrase, + private ?string $privateKeyPath, + private bool $promptForPrivateKey, + private array $processedReplacements, + private ?string $shebang, + private string $signingAlgorithm, + private ?string $stubBannerContents, + private ?string $stubBannerPath, + private ?string $stubPath, + private bool $isInterceptFileFuncs, + private bool $isStubGenerated, + private bool $checkRequirements, + private array $warnings, + private array $recommendations, ) { } diff --git a/src/Console/Application.php b/src/Console/Application.php index 47d6e209b..193959766 100644 --- a/src/Console/Application.php +++ b/src/Console/Application.php @@ -15,6 +15,17 @@ namespace KevinGH\Box\Console; use Fidry\Console\Application\Application as FidryApplication; +use KevinGH\Box\Console\Command\Compile; +use KevinGH\Box\Console\Command\Composer\ComposerCheckVersion; +use KevinGH\Box\Console\Command\Composer\ComposerVendorDir; +use KevinGH\Box\Console\Command\Diff; +use KevinGH\Box\Console\Command\Extract; +use KevinGH\Box\Console\Command\GenerateDockerFile; +use KevinGH\Box\Console\Command\Info; +use KevinGH\Box\Console\Command\Namespace_; +use KevinGH\Box\Console\Command\Process; +use KevinGH\Box\Console\Command\Validate; +use KevinGH\Box\Console\Command\Verify; use function KevinGH\Box\get_box_version; use function sprintf; use function trim; @@ -24,16 +35,16 @@ */ final class Application implements FidryApplication { - private string $version; - private string $releaseDate; + private readonly string $version; + private readonly string $releaseDate; private string $header; public function __construct( - private string $name = 'Box', + private readonly string $name = 'Box', ?string $version = null, string $releaseDate = '@release-date@', - private bool $autoExit = true, - private bool $catchExceptions = true, + private readonly bool $autoExit = true, + private readonly bool $catchExceptions = true, ) { $this->version = $version ?? get_box_version(); $this->releaseDate = !str_contains($releaseDate, '@') ? $releaseDate : ''; @@ -78,17 +89,17 @@ public function getHeader(): string public function getCommands(): array { return [ - new Command\Composer\ComposerCheckVersion(), - new Command\Composer\ComposerVendorDir(), - new Command\Compile($this->getHeader()), - new Command\Diff(), - new Command\Info(), - new Command\Process(), - new Command\Extract(), - new Command\Validate(), - new Command\Verify(), - new Command\GenerateDockerFile(), - new Command\Namespace_(), + new ComposerCheckVersion(), + new ComposerVendorDir(), + new Compile($this->getHeader()), + new Diff(), + new Info(), + new Process(), + new Extract(), + new Validate(), + new Verify(), + new GenerateDockerFile(), + new Namespace_(), ]; } diff --git a/src/Console/Command/Compile.php b/src/Console/Command/Compile.php index 33d231208..6e1598f4c 100644 --- a/src/Console/Command/Compile.php +++ b/src/Console/Command/Compile.php @@ -111,7 +111,7 @@ final class Compile implements CommandAware private const DEBUG_DIR = '.box_dump'; - public function __construct(private string $header) + public function __construct(private readonly string $header) { } diff --git a/src/Console/Logger/CompilerLogger.php b/src/Console/Logger/CompilerLogger.php index 5b19775f5..2cd3bc034 100644 --- a/src/Console/Logger/CompilerLogger.php +++ b/src/Console/Logger/CompilerLogger.php @@ -22,7 +22,7 @@ /** * @internal */ -final class CompilerLogger +final readonly class CompilerLogger { public const QUESTION_MARK_PREFIX = '?'; public const STAR_PREFIX = '*'; @@ -30,7 +30,7 @@ final class CompilerLogger public const MINUS_PREFIX = '-'; public const CHEVRON_PREFIX = '>'; - public function __construct(private readonly IO $io) + public function __construct(private IO $io) { } diff --git a/src/Console/Php/PhpSettingsHandler.php b/src/Console/Php/PhpSettingsHandler.php index 059716b90..59120dd0f 100644 --- a/src/Console/Php/PhpSettingsHandler.php +++ b/src/Console/Php/PhpSettingsHandler.php @@ -34,8 +34,8 @@ */ final class PhpSettingsHandler extends XdebugHandler { - private LoggerInterface $logger; - private bool $pharReadonly; + private readonly LoggerInterface $logger; + private readonly bool $pharReadonly; public function __construct(LoggerInterface $logger) { diff --git a/src/DockerFileGenerator.php b/src/DockerFileGenerator.php index f8ae840a9..39c36b2f4 100644 --- a/src/DockerFileGenerator.php +++ b/src/DockerFileGenerator.php @@ -55,12 +55,12 @@ final class DockerFileGenerator '7.0.0' => '7-cli-alpine', ]; - private string $image; + private readonly string $image; /** * @var string[] */ - private array $extensions; + private readonly array $extensions; /** * Creates a new instance of the generator. diff --git a/src/Json/Json.php b/src/Json/Json.php index a49b999fd..823c0881f 100644 --- a/src/Json/Json.php +++ b/src/Json/Json.php @@ -28,7 +28,7 @@ /** * @private */ -final class Json +final readonly class Json { private JsonParser $linter; diff --git a/src/Json/JsonValidationException.php b/src/Json/JsonValidationException.php index 288837755..2e6990f6a 100644 --- a/src/Json/JsonValidationException.php +++ b/src/Json/JsonValidationException.php @@ -23,8 +23,8 @@ */ final class JsonValidationException extends UnexpectedValueException { - private ?string $validatedFile; - private array $errors; + private readonly ?string $validatedFile; + private readonly array $errors; /** * @param string[] $errors diff --git a/src/MapFile.php b/src/MapFile.php index 2bedefd79..bf23c7507 100644 --- a/src/MapFile.php +++ b/src/MapFile.php @@ -23,7 +23,7 @@ * * @private */ -final class MapFile +final readonly class MapFile { /** * @param string[][] $map diff --git a/src/Phar/Differ/ChecksumDiffer.php b/src/Phar/Differ/ChecksumDiffer.php index 06121135d..02c59e57e 100644 --- a/src/Phar/Differ/ChecksumDiffer.php +++ b/src/Phar/Differ/ChecksumDiffer.php @@ -21,7 +21,7 @@ use function hash; use function implode; -final class ChecksumDiffer implements Differ +final readonly class ChecksumDiffer implements Differ { public function __construct( private string $checksumAlgorithm, diff --git a/src/Phar/Differ/ProcessCommandBasedDiffer.php b/src/Phar/Differ/ProcessCommandBasedDiffer.php index eab2442a1..ba820877b 100644 --- a/src/Phar/Differ/ProcessCommandBasedDiffer.php +++ b/src/Phar/Differ/ProcessCommandBasedDiffer.php @@ -18,7 +18,7 @@ use KevinGH\Box\Phar\PharInfo; use Symfony\Component\Process\Process; -final class ProcessCommandBasedDiffer implements Differ +final readonly class ProcessCommandBasedDiffer implements Differ { public function __construct(private string $command) { diff --git a/src/Phar/PharInfo.php b/src/Phar/PharInfo.php index a71723cb1..2865938b9 100644 --- a/src/Phar/PharInfo.php +++ b/src/Phar/PharInfo.php @@ -77,16 +77,16 @@ final class PharInfo private static array $ALGORITHMS; private static string $stubfile; - private PharMeta $meta; - private string $tmp; - private string $file; - private string $fileName; + private readonly PharMeta $meta; + private readonly string $tmp; + private readonly string $file; + private readonly string $fileName; private array $compressionCount; /** * @var array */ - private array $files; + private readonly array $files; public function __construct(string $file) { diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index af51a3a4b..7df2d7b17 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -36,7 +36,7 @@ * * @private */ -final class PharMeta +final readonly class PharMeta { /** * @param non-empty-string|null $stub @@ -46,15 +46,15 @@ final class PharMeta * @param array $filesMeta */ public function __construct( - public readonly CompressionAlgorithm $compression, + public CompressionAlgorithm $compression, #[ArrayShape(['hash' => 'string', 'hash_type' => 'string'])] - public readonly ?array $signature, - public readonly ?string $stub, - public readonly ?string $version, - public readonly ?string $normalizedMetadata, - public readonly int $timestamp, - public readonly ?string $pubKeyContent, - public readonly array $filesMeta, + public ?array $signature, + public ?string $stub, + public ?string $version, + public ?string $normalizedMetadata, + public int $timestamp, + public ?string $pubKeyContent, + public array $filesMeta, ) { } diff --git a/src/PhpScoper/ExcludedFilesScoper.php b/src/PhpScoper/ExcludedFilesScoper.php index fd3c8f90c..b99f3e69a 100644 --- a/src/PhpScoper/ExcludedFilesScoper.php +++ b/src/PhpScoper/ExcludedFilesScoper.php @@ -21,10 +21,10 @@ final class ExcludedFilesScoper implements PhpScoperScoper { - private array $excludedFilePathsAsKeys; + private readonly array $excludedFilePathsAsKeys; public function __construct( - private PhpScoperScoper $decoratedScoper, + private readonly PhpScoperScoper $decoratedScoper, string ...$excludedFilePaths, ) { $this->excludedFilePathsAsKeys = array_flip($excludedFilePaths); diff --git a/src/PhpScoper/SerializablePatcher.php b/src/PhpScoper/SerializablePatcher.php index 14f51d7c0..c436b3b61 100644 --- a/src/PhpScoper/SerializablePatcher.php +++ b/src/PhpScoper/SerializablePatcher.php @@ -22,7 +22,7 @@ /** * @var PatcherCallable = (string $filePath, string $prefix, string $contents): string */ -final class SerializablePatcher implements Patcher +final readonly class SerializablePatcher implements Patcher { public static function create(callable $patcher): self { diff --git a/src/PhpScoper/SerializableScoper.php b/src/PhpScoper/SerializableScoper.php index 152c00e87..d9b845a0d 100644 --- a/src/PhpScoper/SerializableScoper.php +++ b/src/PhpScoper/SerializableScoper.php @@ -25,7 +25,7 @@ */ final class SerializableScoper implements Scoper { - private PhpScoperConfiguration $scoperConfig; + private readonly PhpScoperConfiguration $scoperConfig; private PhpScoperContainer $scoperContainer; private PhpScoperScoper $scoper; private SymbolsRegistry $symbolsRegistry; diff --git a/src/RequirementChecker/DecodedComposerJson.php b/src/RequirementChecker/DecodedComposerJson.php index 01e0fb953..326882a9b 100644 --- a/src/RequirementChecker/DecodedComposerJson.php +++ b/src/RequirementChecker/DecodedComposerJson.php @@ -19,12 +19,12 @@ /** * @private */ -final class DecodedComposerJson +final readonly class DecodedComposerJson { /** * @param array $composerJsonDecodedContents Decoded JSON contents of the `composer.json` file */ - public function __construct(private readonly array $composerJsonDecodedContents) + public function __construct(private array $composerJsonDecodedContents) { } diff --git a/src/RequirementChecker/DecodedComposerLock.php b/src/RequirementChecker/DecodedComposerLock.php index ba5d7f473..651b64527 100644 --- a/src/RequirementChecker/DecodedComposerLock.php +++ b/src/RequirementChecker/DecodedComposerLock.php @@ -19,12 +19,12 @@ /** * @private */ -final class DecodedComposerLock +final readonly class DecodedComposerLock { /** * @param array $composerLockDecodedContents Decoded JSON contents of the `composer.lock` file */ - public function __construct(private readonly array $composerLockDecodedContents) + public function __construct(private array $composerLockDecodedContents) { } diff --git a/src/RequirementChecker/PackageInfo.php b/src/RequirementChecker/PackageInfo.php index 3ff05aa25..5f4fbf8ad 100644 --- a/src/RequirementChecker/PackageInfo.php +++ b/src/RequirementChecker/PackageInfo.php @@ -19,7 +19,7 @@ /** * @private */ -final class PackageInfo +final readonly class PackageInfo { private const EXTENSION_REGEX = '/^ext-(?.+)$/'; @@ -37,7 +37,7 @@ final class PackageInfo private const SYMFONY_POLYFILL_REGEX = '/symfony\/polyfill-(?.+)/'; - public function __construct(private readonly array $packageInfo) + public function __construct(private array $packageInfo) { } diff --git a/src/RequirementChecker/RequiredItem.php b/src/RequirementChecker/RequiredItem.php index 5bd38e19e..9036d426b 100644 --- a/src/RequirementChecker/RequiredItem.php +++ b/src/RequirementChecker/RequiredItem.php @@ -20,7 +20,7 @@ /** * @private */ -final class RequiredItem +final readonly class RequiredItem { private const POLYFILL_MAP = [ 'paragonie/sodium_compat' => 'libsodium', @@ -32,7 +32,7 @@ final class RequiredItem /** * @param array $packageInfo */ - public function __construct(private readonly array $packageInfo) + public function __construct(private array $packageInfo) { } diff --git a/src/RequirementChecker/Requirement.php b/src/RequirementChecker/Requirement.php index 73feb9a7d..fe1d8e3ef 100644 --- a/src/RequirementChecker/Requirement.php +++ b/src/RequirementChecker/Requirement.php @@ -17,14 +17,14 @@ /** * @private */ -final class Requirement +final readonly class Requirement { public function __construct( - public readonly RequirementType $type, - public readonly string $condition, - public readonly ?string $source, - public readonly string $message, - public readonly string $helpMessage, + public RequirementType $type, + public string $condition, + public ?string $source, + public string $message, + public string $helpMessage, ) { } diff --git a/tests/Benchmark/BenchResultReaderTest.php b/tests/Benchmark/BenchResultReaderTest.php index 7ef718330..6117a5ab5 100644 --- a/tests/Benchmark/BenchResultReaderTest.php +++ b/tests/Benchmark/BenchResultReaderTest.php @@ -220,9 +220,9 @@ public static function xmlProvider(): iterable yield [ $xml, [ - 'no compactors' => 2638316.8, - 'with compactors; no parallel processing' => 2612822.4, - 'with compactors; parallel processing' => 2967538.1, + 'no compactors' => 2_638_316.8, + 'with compactors; no parallel processing' => 2_612_822.4, + 'with compactors; parallel processing' => 2_967_538.1, ], ]; } diff --git a/tests/Benchmark/CompileBench.php b/tests/Benchmark/CompileBench.php index 589bce627..865fd8871 100644 --- a/tests/Benchmark/CompileBench.php +++ b/tests/Benchmark/CompileBench.php @@ -28,7 +28,7 @@ use Symfony\Component\Console\Output\NullOutput; use function Safe\chdir; -final class CompileBench +final readonly class CompileBench { private const WITHOUT_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/without-compactors'; private const WITH_COMPACTORS_DIR = __DIR__.'/../../fixtures/bench/with-compactors'; diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index cd7aa24af..b86d3c659 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -84,7 +84,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1559806605, + 1_559_806_605, null, [ '.hidden' => [ @@ -131,7 +131,7 @@ private static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1559807994, + 1_559_807_994, null, [ '.hidden' => [ @@ -160,7 +160,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531272, + 1_374_531_272, null, [ 'index.php' => [ @@ -189,7 +189,7 @@ private static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531313, + 1_374_531_313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -324,7 +324,7 @@ public function test_it_cannot_extract_an_invalid_phar(string $pharPath): void ); self::assertSame(ExitCode::FAILURE, $this->commandTester->getStatusCode()); - } catch (InvalidPhar $exception) { + } catch (InvalidPhar) { // Continue } diff --git a/tests/Phar/PharMetaTest.php b/tests/Phar/PharMetaTest.php index 7dde21c9a..8396776c8 100644 --- a/tests/Phar/PharMetaTest.php +++ b/tests/Phar/PharMetaTest.php @@ -47,7 +47,7 @@ public static function pharMetaProvider(): iterable null, null, null, - 1509920675, + 1_509_920_675, null, [], ), @@ -64,7 +64,7 @@ public static function pharMetaProvider(): iterable 'action' => 'sayHello', ) EOL, - 1509920675, + 1_509_920_675, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -123,7 +123,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680285013, + 1_680_285_013, null, [ 'sample.php' => [ @@ -146,7 +146,7 @@ public static function pharProvider(): iterable $oldDefaultPharStub, '1.1.0', null, - 1509920675, + 1_509_920_675, null, [ 'foo.php' => [ @@ -169,7 +169,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680680933, + 1_680_680_933, null, [ 'sample.php' => [ @@ -197,7 +197,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680469485, + 1_680_469_485, null, [ 'sample.php' => [ @@ -222,7 +222,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680469504, + 1_680_469_504, null, [ 'sample.php' => [ @@ -246,7 +246,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531272, + 1_374_531_272, null, [ 'index.php' => [ @@ -269,7 +269,7 @@ public static function pharProvider(): iterable $sha512Stub, '1.1.0', null, - 1374531313, + 1_374_531_313, <<<'EOF' -----BEGIN PUBLIC KEY----- MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKuZkrHT54KtuBCTrR36+4tibd+2un9b @@ -298,7 +298,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', "'Hello world!'", - 1680366918, + 1_680_366_918, null, [ 'sample.php' => [ @@ -321,7 +321,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', '-19.8', - 1680366947, + 1_680_366_947, null, [ 'sample.php' => [ @@ -348,7 +348,7 @@ public static function pharProvider(): iterable 'action' => 'sayHello', ) EOL, - 1680367053, + 1_680_367_053, null, [ 'sample.php' => [ @@ -368,7 +368,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284754, + 1_680_284_754, null, [ 'sample.txt' => [ @@ -389,7 +389,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284663, + 1_680_284_663, null, [ 'sample.txt' => [ @@ -411,7 +411,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284660, + 1_680_284_660, null, [ 'sample.txt' => [ @@ -433,7 +433,7 @@ public static function pharProvider(): iterable null, null, null, - 1680284663, + 1_680_284_663, null, [ 'sample.txt' => [ @@ -457,7 +457,7 @@ public static function pharProvider(): iterable $defaultStub, '1.1.0', null, - 1680645848, + 1_680_645_848, null, [ '.hidden-dir/.hidden-file' => [ From 10aea92791e9dbeddc3726d2c1a2107c68e90fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= Date: Sat, 25 Nov 2023 10:52:21 +0100 Subject: [PATCH 12/12] fix ci step --- .github/workflows/auto-review.yaml | 8 ++++++++ .github/workflows/requirement-checker.yaml | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/.github/workflows/auto-review.yaml b/.github/workflows/auto-review.yaml index 1ee4494b7..9dbd4aa3a 100644 --- a/.github/workflows/auto-review.yaml +++ b/.github/workflows/auto-review.yaml @@ -45,6 +45,14 @@ jobs: - name: Ensure that the PHP-CS-Fixer make target is up to date run: make php_cs_fixer_install + - name: Install Rector + uses: ramsey/composer-install@v2 + with: + working-directory: vendor-bin/rector + + - name: Ensure that the PHP-CS-Fixer make target is up to date + run: make rector_install + - run: make root_cs_lint composer-validate: diff --git a/.github/workflows/requirement-checker.yaml b/.github/workflows/requirement-checker.yaml index bdf341ec9..6c18066b9 100644 --- a/.github/workflows/requirement-checker.yaml +++ b/.github/workflows/requirement-checker.yaml @@ -48,6 +48,14 @@ jobs: - name: Ensure that the PHP-CS-Fixer make target is up to date run: make php_cs_fixer_install + - name: Install Rector + uses: ramsey/composer-install@v2 + with: + working-directory: vendor-bin/rector + + - name: Ensure that the PHP-CS-Fixer make target is up to date + run: make rector_install + - name: Install the Composer dependencies uses: ramsey/composer-install@v2 with: