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: diff --git a/Makefile b/Makefile index 733138718..7d15e9df1 100644 --- a/Makefile +++ b/Makefile @@ -46,6 +46,9 @@ PHPBENCH = $(PHPBENCH_BIN) PHPBENCH_WITH_COMPACTORS_VENDOR_DIR = fixtures/bench/with-compactors/vendor PHPBENCH_WITHOUT_COMPACTORS_VENDOR_DIR = fixtures/bench/without-compactors/vendor +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 @@ -162,7 +165,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: @@ -174,7 +177,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: @@ -188,6 +191,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 @@ -406,6 +417,18 @@ vendor-bin/phpbench/composer.lock: vendor-bin/phpbench/composer.json @echo "$(ERROR_COLOR)$(@) is not up to date. You may want to run the following command:$(NO_COLOR)" @echo "$$ composer bin phpbench 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) + 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..bfaf4a6a2 100644 --- a/rector.php +++ b/rector.php @@ -19,6 +19,15 @@ $rectorConfig->importNames(); $rectorConfig->sets([ - LevelSetList::UP_TO_PHP_81, + LevelSetList::UP_TO_PHP_82, + ]); + + $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', + ], + \Rector\Php73\Rector\String_\SensitiveHereNowDocRector::class, ]); }; 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..ed8d99de4 --- /dev/null +++ b/requirement-checker/rector-src.php @@ -0,0 +1,22 @@ +paths([ + __DIR__ . '/src', + ]); + + $rectorConfig->sets([ + LevelSetList::UP_TO_PHP_72, + // 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..022c82102 --- /dev/null +++ b/requirement-checker/rector-tests.php @@ -0,0 +1,25 @@ +paths([ + __DIR__ . '/tests', + ]); + + $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(); +}; 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/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/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/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); } } 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' => [ 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" } }