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] 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" } }