From 5c5b486eec2160c422fbabc1492fdedad19a061e Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Tue, 19 Nov 2024 14:56:21 +0100 Subject: [PATCH 1/2] Improve rector config by use syntax, and prepared set methods (#259) --- rector.php | 52 ++++++++++++++-------------------------------------- 1 file changed, 14 insertions(+), 38 deletions(-) diff --git a/rector.php b/rector.php index a43a885f..f21fe731 100644 --- a/rector.php +++ b/rector.php @@ -3,59 +3,35 @@ declare(strict_types=1); use Rector\Config\RectorConfig; -use Rector\Doctrine\Set\DoctrineSetList; -use Rector\PHPUnit\Set\PHPUnitLevelSetList; -use Rector\PHPUnit\Set\PHPUnitSetList; -use Rector\Set\ValueObject\LevelSetList; -use Rector\Set\ValueObject\SetList; -use Rector\Symfony\Set\SymfonyLevelSetList; use Rector\Symfony\Set\SymfonySetList; -use Sulu\Rector\Set\SuluLevelSetList; -return static function (RectorConfig $rectorConfig): void { - $rectorConfig->paths([__DIR__ . '/src', __DIR__ . '/tests']); - - $rectorConfig->phpstanConfigs([ +return RectorConfig::configure() + ->withPaths([ + __DIR__ . '/src', + __DIR__ . '/tests', + ]) + ->withRootFiles() + ->withPHPStanConfigs([ __DIR__ . '/phpstan.dist.neon', // rector does not load phpstan extension automatically so require them manually here: __DIR__ . '/vendor/phpstan/phpstan-doctrine/extension.neon', __DIR__ . '/vendor/phpstan/phpstan-symfony/extension.neon', - ]); - - // basic rules - $rectorConfig->importNames(); - $rectorConfig->importShortClasses(false); - - $rectorConfig->sets([ - SetList::CODE_QUALITY, - LevelSetList::UP_TO_PHP_81, - ]); + ]) + ->withImportNames(importShortClasses: false) + ->withPreparedSets(codeQuality: true, doctrineCodeQuality: true) + ->withPhpSets() // symfony rules - $rectorConfig->symfonyContainerPhp(__DIR__ . '/var/cache/website/dev/App_KernelDevDebugContainer.xml'); - - $rectorConfig->sets([ + ->withSymfonyContainerPhp(__DIR__ . '/var/cache/website/dev/App_KernelDevDebugContainer.xml') + ->withSets([ SymfonySetList::SYMFONY_CODE_QUALITY, SymfonySetList::SYMFONY_CONSTRUCTOR_INJECTION, // activate when doing updates: // SymfonyLevelSetList::UP_TO_SYMFONY_63, - ]); - - // doctrine rules - $rectorConfig->sets([ - DoctrineSetList::DOCTRINE_CODE_QUALITY, - ]); - - // phpunit rules - $rectorConfig->sets([ // activate when doing updates: // PHPUnitLevelSetList::UP_TO_PHPUNIT_90, // PHPUnitSetList::PHPUNIT_91, - ]); - - // sulu rules - $rectorConfig->sets([ + // sulu rules // activate for updates when doing updates: // SuluLevelSetList::UP_TO_SULU_25, ]); -}; From 826a9eeda2087efe769ae1f85a405c234a142bb3 Mon Sep 17 00:00:00 2001 From: Rafael Kraut <14234815+RafaelKr@users.noreply.github.com> Date: Tue, 19 Nov 2024 15:00:12 +0100 Subject: [PATCH 2/2] Fix `composer lint`: phpstan No error to ignore is reported on line 17. (#258) * Bump phpstan/phpstan to ^1.12 This includes a fix to issue https://github.com/phpstan/phpstan/issues/7685 "Cast to (bool) on string|false !== false should end in non-empty-string" * Remove @phpstan-ignore-next-line from config/router.php Since phpstan v1.12.1 the related issue is fixed. https://github.com/phpstan/phpstan/issues/7685 https://github.com/phpstan/phpstan-src/pull/3380 --- composer.json | 2 +- config/router.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index c171ef50..e8dfbeaf 100644 --- a/composer.json +++ b/composer.json @@ -58,7 +58,7 @@ "phpcr/phpcr-shell": "^1.5", "phpspec/prophecy-phpunit": "^2.1", "phpstan/extension-installer": "^1.3", - "phpstan/phpstan": "^1.10", + "phpstan/phpstan": "^1.12", "phpstan/phpstan-doctrine": "^1.3", "phpstan/phpstan-phpunit": "^1.3", "phpstan/phpstan-symfony": "^1.3", diff --git a/config/router.php b/config/router.php index 3d6a2109..e0b69688 100644 --- a/config/router.php +++ b/config/router.php @@ -13,7 +13,6 @@ // Workaround https://bugs.php.net/64566 $autoPrependFile = \ini_get('auto_prepend_file'); -// @phpstan-ignore-next-line https://github.com/phpstan/phpstan/issues/7685 if (false !== (bool) $autoPrependFile && !\in_array(\realpath($autoPrependFile), \get_included_files(), true)) { require \ini_get('auto_prepend_file'); }