diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index a2fbfb73..456c25fa 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -18,9 +18,6 @@ jobs: fail-fast: false matrix: include: - - php-version: "8.0" - drupal: "^9.2" - fixture: "d9" - php-version: "8.1" drupal: "^10.0" fixture: "d10" diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index af3574ca..537e5b5c 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -15,6 +15,15 @@ jobs: name: Static analysis with PHPStan # START: SHARED SETUP runs-on: ubuntu-latest + strategy: + matrix: + include: + - php-version: "8.2" + rector: "^1" + phpstan-config: phpstan-1.neon + - php-version: "8.2" + rector: "^2" + phpstan-config: phpstan.neon steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 @@ -28,5 +37,5 @@ jobs: # uses: mxschmitt/action-tmate@v2 # END: SHARED SETUP - - run: composer install - - run: composer phpstan + - run: composer require rector/rector:${{ matrix.rector }} --dev + - run: vendor/bin/phpstan analyse -c ${{ matrix.phpstan-config }} diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 5af6600d..0678b2f8 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -12,12 +12,15 @@ on: jobs: tests: - name: 'PHPUnit | PHP ${{ matrix.php-version }}' + name: 'PHPUnit | rector/rector:${{ matrix.rector }}' runs-on: ubuntu-latest strategy: matrix: - php-version: - - "8.2" + include: + - php-version: "8.2" + rector: "^1" + - php-version: "8.2" + rector: "^2" steps: - uses: actions/checkout@v3 - uses: shivammathur/setup-php@v2 @@ -25,5 +28,5 @@ jobs: php-version: ${{ matrix.php-version }} coverage: none tools: composer:v2 - - run: composer install + - run: composer require rector/rector:${{ matrix.rector }} --dev - run: composer test diff --git a/composer.json b/composer.json index 537f672b..996ac159 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "ast" ], "require": { - "rector/rector": "^1.0", + "rector/rector": "^1 || ^2", "webflo/drupal-finder": "^1.2" }, "license": "MIT", @@ -76,9 +76,9 @@ "php": "^8.2", "cweagans/composer-patches": "^1.7.2", "friendsofphp/php-cs-fixer": "^3.58", - "phpstan/extension-installer": "^1.1", - "phpstan/phpstan": "^1.0", - "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/extension-installer": "^1.4.3", + "phpstan/phpstan": "^1.12 || ^2.0", + "phpstan/phpstan-deprecation-rules": "^1.2 || ^2.0", "phpunit/phpunit": "^10.0", "symfony/yaml": "^5 || ^6 || ^7", "symplify/vendor-patches": "^11.0" diff --git a/config/drupal-10/drupal-10.0-deprecations.php b/config/drupal-10/drupal-10.0-deprecations.php index 1c9e42f8..b27b02f2 100644 --- a/config/drupal-10/drupal-10.0-deprecations.php +++ b/config/drupal-10/drupal-10.0-deprecations.php @@ -9,6 +9,12 @@ use Rector\Symfony\Set\TwigSetList; return static function (RectorConfig $rectorConfig): void { + if (defined('TwigSetList::TWIG_24')) { + $twigSet = TwigSetList::TWIG_24; + } else { + $twigSet = TwigSetList::TWIG_240; + } + $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_90, SymfonySetList::SYMFONY_50, @@ -19,7 +25,7 @@ SymfonySetList::SYMFONY_60, SymfonySetList::SYMFONY_61, SymfonySetList::SYMFONY_62, - TwigSetList::TWIG_240, + $twigSet, ]); $rectorConfig->rule(ShouldCallParentMethodsRector::class); diff --git a/config/drupal-9/drupal-9.0-deprecations.php b/config/drupal-9/drupal-9.0-deprecations.php index e981836e..035f0dfd 100644 --- a/config/drupal-9/drupal-9.0-deprecations.php +++ b/config/drupal-9/drupal-9.0-deprecations.php @@ -15,6 +15,12 @@ return new AddCommentService(); }); + if (defined('TwigSetList::TWIG_24')) { + $twigSet = TwigSetList::TWIG_24; + } else { + $twigSet = TwigSetList::TWIG_240; + } + $rectorConfig->sets([ PHPUnitSetList::PHPUNIT_80, SymfonySetList::SYMFONY_40, @@ -22,7 +28,7 @@ SymfonySetList::SYMFONY_42, SymfonySetList::SYMFONY_43, SymfonySetList::SYMFONY_44, - TwigSetList::TWIG_240, + $twigSet, ]); $rectorConfig->rule(ProtectedStaticModulesPropertyRector::class); diff --git a/phpstan-1-baseline.neon b/phpstan-1-baseline.neon new file mode 100644 index 00000000..b9ccb198 --- /dev/null +++ b/phpstan-1-baseline.neon @@ -0,0 +1,159 @@ +parameters: + ignoreErrors: + - + message: "#^Access to undefined constant Rector\\\\Symfony\\\\Set\\\\TwigSetList\\:\\:TWIG_24\\.$#" + count: 1 + path: config/drupal-10/drupal-10.0-deprecations.php + + - + message: "#^Access to undefined constant Rector\\\\Symfony\\\\Set\\\\TwigSetList\\:\\:TWIG_24\\.$#" + count: 1 + path: config/drupal-9/drupal-9.0-deprecations.php + + - + message: """ + #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: + Will be removed in v2\\. Future usage should instantiate + a new DrupalFinder object by passing the starting path to its + constructor\\.$# + """ + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_contrib_extension_directory_roots\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_find_extension_directories\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) has parameter \\$dirs with no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) return type has no value type specified in iterable type array\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has no return type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$drupalRoot with no type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$vendorRoot with no type specified\\.$#" + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: """ + #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: + in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. + Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# + """ + count: 1 + path: config/drupal-phpunit-bootstrap-file.php + + - + message: """ + #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: + Will be removed in v2\\. Future usage should instantiate + a new DrupalFinder object by passing the starting path to its + constructor\\.$# + """ + count: 1 + path: rector.php + + - + message: """ + #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: + in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. + Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# + """ + count: 1 + path: rector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$value\\.$#" + count: 2 + path: src/Drupal8/Rector/Deprecation/DBRector.php + + - + message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityLoadRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + count: 2 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$name\\.$#" + count: 3 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:getServiceByMethodName\\(\\) has no return type specified\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^PHPDoc tag @param references unknown parameter\\: \\$node$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:findInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:replaceInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node\\\\Expr given\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Property PhpParser\\\\Node\\\\Expr\\\\Assign\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + + - + message: "#^Calling PHPStan\\\\Php\\\\PhpVersionFactory\\:\\:create\\(\\) is not covered by backward compatibility promise\\. The method might change in a minor PHPStan version\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: "#^Method PHPStan\\\\Type\\\\Type\\:\\:isSmallerThanOrEqual\\(\\) invoked with 2 parameters, 1 required\\.$#" + count: 1 + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php + + - + message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + count: 1 + path: src/Drupal9/Rector/Deprecation/ExtensionPathRector.php diff --git a/phpstan-1.neon b/phpstan-1.neon new file mode 100644 index 00000000..74e16606 --- /dev/null +++ b/phpstan-1.neon @@ -0,0 +1,12 @@ +parameters: + level: 6 + paths: + - config + - src + - rector.php + bootstrapFiles: + - vendor/rector/rector/vendor/autoload.php + dynamicConstantNames: + - Drupal::VERSION +includes: + - phpstan-1-baseline.neon diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 38ca9036..74b1ed9c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,181 +1,241 @@ parameters: ignoreErrors: - - message: """ - #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: - Will be removed in v2\\. Future usage should instantiate + message: '#^Access to undefined constant Rector\\Symfony\\Set\\TwigSetList\:\:TWIG_240\.$#' + identifier: classConstant.notFound + count: 1 + path: config/drupal-10/drupal-10.0-deprecations.php + + - + message: '#^Access to undefined constant Rector\\Symfony\\Set\\TwigSetList\:\:TWIG_240\.$#' + identifier: classConstant.notFound + count: 1 + path: config/drupal-9/drupal-9.0-deprecations.php + + - + message: ''' + #^Call to deprecated method locateRoot\(\) of class DrupalFinder\\DrupalFinder\: + Will be removed in v2\. Future usage should instantiate a new DrupalFinder object by passing the starting path to its - constructor\\.$# - """ + constructor\.$# + ''' + identifier: method.deprecated count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_contrib_extension_directory_roots\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_contrib_extension_directory_roots\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_find_extension_directories\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_find_extension_directories\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) has parameter \\$dirs with no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_get_extension_namespaces\(\) has parameter \$dirs with no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_get_extension_namespaces\\(\\) return type has no value type specified in iterable type array\\.$#" + message: '#^Function drupal_phpunit_get_extension_namespaces\(\) return type has no value type specified in iterable type array\.$#' + identifier: missingType.iterableValue count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has no return type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$drupalRoot with no type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has parameter \$drupalRoot with no type specified\.$#' + identifier: missingType.parameter count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: "#^Function drupal_phpunit_populate_class_loader\\(\\) has parameter \\$vendorRoot with no type specified\\.$#" + message: '#^Function drupal_phpunit_populate_class_loader\(\) has parameter \$vendorRoot with no type specified\.$#' + identifier: missingType.parameter count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: """ - #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: - in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. - Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# - """ + message: ''' + #^Instantiation of deprecated class DrupalFinder\\DrupalFinder\: + in drupal\-finder\:1\.3\.0 and is removed from drupal\-finder\:2\.0\.0\. + Use \\DrupalFinder\\DrupalFinderComposerRuntime instead\.$# + ''' + identifier: new.deprecated count: 1 path: config/drupal-phpunit-bootstrap-file.php - - message: """ - #^Call to deprecated method locateRoot\\(\\) of class DrupalFinder\\\\DrupalFinder\\: - Will be removed in v2\\. Future usage should instantiate + message: ''' + #^Call to deprecated method locateRoot\(\) of class DrupalFinder\\DrupalFinder\: + Will be removed in v2\. Future usage should instantiate a new DrupalFinder object by passing the starting path to its - constructor\\.$# - """ + constructor\.$# + ''' + identifier: method.deprecated count: 1 path: rector.php - - message: """ - #^Instantiation of deprecated class DrupalFinder\\\\DrupalFinder\\: - in drupal\\-finder\\:1\\.3\\.0 and is removed from drupal\\-finder\\:2\\.0\\.0\\. - Use \\\\DrupalFinder\\\\DrupalFinderComposerRuntime instead\\.$# - """ + message: ''' + #^Instantiation of deprecated class DrupalFinder\\DrupalFinder\: + in drupal\-finder\:1\.3\.0 and is removed from drupal\-finder\:2\.0\.0\. + Use \\DrupalFinder\\DrupalFinderComposerRuntime instead\.$# + ''' + identifier: new.deprecated count: 1 path: rector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$value\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$value\.$#' + identifier: property.notFound count: 2 path: src/Drupal8/Rector/Deprecation/DBRector.php - - message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + message: '#^Call to an undefined method PHPStan\\Type\\Type\:\:getValue\(\)\.$#' + identifier: method.notFound count: 1 path: src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr\.$#' + identifier: property.notFound count: 1 path: src/Drupal8/Rector/Deprecation/EntityLoadRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$expr\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$expr\.$#' + identifier: property.notFound count: 2 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Access to an undefined property PhpParser\\\\Node\\\\Expr\\:\\:\\$name\\.$#" + message: '#^Access to an undefined property PhpParser\\Node\\Expr\:\:\$name\.$#' + identifier: property.notFound count: 3 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:getServiceByMethodName\\(\\) has no return type specified\\.$#" + message: '#^Method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:getServiceByMethodName\(\) has no return type specified\.$#' + identifier: missingType.return count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$node$#" + message: '#^PHPDoc tag @param references unknown parameter\: \$node$#' + identifier: parameter.notFound count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:findInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$assign of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:findInstanceByNameInAssign\(\) expects PhpParser\\Node\\Expr\\Assign, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$assign of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:replaceInstanceByNameInAssign\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\Assign, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$assign of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:replaceInstanceByNameInAssign\(\) expects PhpParser\\Node\\Expr\\Assign, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node given\\.$#" + message: '#^Parameter \#1 \$expr of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:refactorExpression\(\) expects PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\StaticCall, PhpParser\\Node given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Parameter \\#1 \\$expr of method DrupalRector\\\\Drupal8\\\\Rector\\\\Deprecation\\\\EntityManagerRector\\:\\:refactorExpression\\(\\) expects PhpParser\\\\Node\\\\Expr\\\\MethodCall\\|PhpParser\\\\Node\\\\Expr\\\\StaticCall, PhpParser\\\\Node\\\\Expr given\\.$#" + message: '#^Parameter \#1 \$expr of method DrupalRector\\Drupal8\\Rector\\Deprecation\\EntityManagerRector\:\:refactorExpression\(\) expects PhpParser\\Node\\Expr\\MethodCall\|PhpParser\\Node\\Expr\\StaticCall, PhpParser\\Node\\Expr given\.$#' + identifier: argument.type count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Property PhpParser\\\\Node\\\\Expr\\\\Assign\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\.$#" + message: '#^Property PhpParser\\Node\\Expr\\Assign\:\:\$expr \(PhpParser\\Node\\Expr\) does not accept PhpParser\\Node\.$#' + identifier: assign.propertyType count: 1 path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php - - message: "#^Property PhpParser\\\\Node\\\\Stmt\\\\Expression\\:\\:\\$expr \\(PhpParser\\\\Node\\\\Expr\\) does not accept PhpParser\\\\Node\\|null\\.$#" + message: '#^Although PHPStan\\Reflection\\Php\\PhpPropertyReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption count: 1 - path: src/Drupal8/Rector/Deprecation/EntityManagerRector.php + path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php - - message: "#^Doing instanceof PHPStan\\\\Type\\\\ObjectType is error\\-prone and deprecated\\. Use Type\\:\\:isObject\\(\\) or Type\\:\\:getObjectClassNames\\(\\) instead\\.$#" + message: '#^Calling PHPStan\\Php\\PhpVersionFactory\:\:create\(\) is not covered by backward compatibility promise\. The method might change in a minor PHPStan version\.$#' + identifier: phpstanApi.method count: 1 path: src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php - - message: "#^Call to an undefined method PHPStan\\\\Type\\\\Type\\:\\:getValue\\(\\)\\.$#" + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertLegacyTraitRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertNoFieldByNameRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/ConstructFieldXpathRector.php + + - + message: '#^Call to an undefined method PHPStan\\Type\\Type\:\:getValue\(\)\.$#' + identifier: method.notFound count: 1 path: src/Drupal9/Rector/Deprecation/ExtensionPathRector.php - - message: """ - #^Fetching deprecated class constant REMOVE_NODE of class PhpParser\\\\NodeTraverser\\: - Use NodeVisitor\\:\\:REMOVE_NODE instead\\.$# - """ + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption count: 1 - path: src/Drupal9/Rector/Deprecation/PassRector.php + path: src/Drupal9/Rector/Deprecation/FromUriRector.php + + - + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption + count: 1 + path: src/Drupal9/Rector/Deprecation/GetAllOptionsRector.php - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal10SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption count: 1 - path: src/Set/Drupal10SetList.php + path: src/Drupal9/Rector/Deprecation/GetRawContentRector.php - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal8SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ + message: '#^Although PHPStan\\Reflection\\Php\\PhpMethodReflection is covered by backward compatibility promise, this instanceof assumption might break because it''s not guaranteed to always stay the same\.$#' + identifier: phpstanApi.instanceofAssumption count: 1 - path: src/Set/Drupal8SetList.php + path: src/Drupal9/Rector/Deprecation/PassRector.php - - message: """ - #^Class DrupalRector\\\\Set\\\\Drupal9SetList implements deprecated interface Rector\\\\Set\\\\Contract\\\\SetListInterface\\: - This interface needs a reflection to load and uses constant links\\. Now we changed to services provider architecture that can be used and registerd easily\\. Use$# - """ + message: '#^Parameter \#3 \$args of method Rector\\PhpParser\\Node\\NodeFactory\:\:createStaticCall\(\) expects array\, array\ given\.$#' + identifier: argument.type count: 1 - path: src/Set/Drupal9SetList.php + path: src/Rector/AbstractDrupalCoreRector.php diff --git a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php index ba2b311b..7497fd53 100644 --- a/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php +++ b/src/Drupal10/Rector/Deprecation/AnnotationToAttributeRector.php @@ -130,6 +130,9 @@ public function getNodeTypes(): array return [Class_::class]; } + /** + * @return PhpVersion::PHP_81 + */ public function provideMinPhpVersion(): int { return PhpVersion::PHP_81; @@ -186,17 +189,22 @@ protected function refactorWithConfiguration(Node $node, VersionedConfigurationI $docBlockHasChanged = \false; foreach ($tagsByName as $valueNode) { - if (!$valueNode->value instanceof GenericTagValueNode) { + if (!$valueNode->value instanceof GenericTagValueNode && !$valueNode->value instanceof DoctrineAnnotationTagValueNode) { continue; } if ($hasAttribute === false) { - $stringValue = $valueNode->value->value; - $stringValue = '{'.trim($stringValue, '()').'}'; - $tokenIterator = $this->tokenIteratorFactory->create($stringValue); - $data = $this->arrayParser->parseCurlyArray($tokenIterator, $node); - $attribute = $this->createAttribute($configuration->getAttributeClass(), $data); - $node->attrGroups[] = new AttributeGroup([$attribute]); + if ($valueNode->value instanceof GenericTagValueNode) { + $stringValue = $valueNode->value->value; + $stringValue = '{'.trim($stringValue, '()').'}'; + $tokenIterator = $this->tokenIteratorFactory->create($stringValue); + $data = $this->arrayParser->parseCurlyArray($tokenIterator, $node); + $attribute = $this->createAttribute($configuration->getAttributeClass(), $data); + $node->attrGroups[] = new AttributeGroup([$attribute]); + } elseif ($valueNode->value instanceof DoctrineAnnotationTagValueNode) { + $attribute = $this->createAttribute($configuration->getAttributeClass(), $valueNode->value->values); + $node->attrGroups[] = new AttributeGroup([$attribute]); + } } if (version_compare($this->installedDrupalVersion(), $configuration->getRemoveVersion(), '>=')) { diff --git a/src/Drupal8/Rector/Deprecation/DBRector.php b/src/Drupal8/Rector/Deprecation/DBRector.php index 4963b5f7..d4c6df70 100644 --- a/src/Drupal8/Rector/Deprecation/DBRector.php +++ b/src/Drupal8/Rector/Deprecation/DBRector.php @@ -56,7 +56,7 @@ class DBRector extends AbstractRector implements ConfigurableRectorInterface protected $optionsArgumentPosition; /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\DBConfiguration[] + * @var DBConfiguration[] */ private array $configuration; diff --git a/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php b/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php index 43726353..61b17330 100644 --- a/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php +++ b/src/Drupal8/Rector/Deprecation/DrupalServiceRenameRector.php @@ -14,7 +14,7 @@ class DrupalServiceRenameRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\DrupalServiceRenameConfiguration[] + * @var DrupalServiceRenameConfiguration[] */ protected array $staticArgumentRenameConfigs = []; diff --git a/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php b/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php index 4d3addba..caf66587 100644 --- a/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php +++ b/src/Drupal8/Rector/Deprecation/DrupalSetMessageRector.php @@ -84,7 +84,6 @@ public function refactor(Node $node): ?Node } $expression = $node->expr; - assert($expression instanceof Node\Expr\FuncCall); if ($this->getName($expression->name) === 'drupal_set_message') { $scope = $node->getAttribute(AttributeKey::SCOPE); diff --git a/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php b/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php index 31b85b90..9ffc0274 100644 --- a/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityInterfaceLinkRector.php @@ -87,7 +87,7 @@ public function refactor(Node $node): ?Node return $node; } - if ($node->expr instanceof Node\Expr\Assign && $node->expr->expr instanceof Node\Expr\MethodCall) { + if ($node->expr->expr instanceof Node\Expr\MethodCall) { $methodCall = $this->getMethodCall($node->expr->expr, $node); $node->expr->expr = $methodCall; diff --git a/src/Drupal8/Rector/Deprecation/EntityLoadRector.php b/src/Drupal8/Rector/Deprecation/EntityLoadRector.php index 7c3bb7fa..66b5e5b5 100644 --- a/src/Drupal8/Rector/Deprecation/EntityLoadRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityLoadRector.php @@ -27,7 +27,7 @@ final class EntityLoadRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal8\Rector\ValueObject\EntityLoadConfiguration[] + * @var EntityLoadConfiguration[] */ protected array $entityTypes; diff --git a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php index 9cfb53b5..4bbb78c5 100644 --- a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php @@ -148,7 +148,7 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla $depth = 0; // Should the expression be the class we are looking for and the name is the one we are looking for, we can return early. - if ($node instanceof Node && $node instanceof $class && $this->getName($node->name) === $name) { + if ($node instanceof $class && $this->getName($node->name) === $name) { $node->setAttribute(self::class, $depth); return $node; @@ -183,9 +183,9 @@ public function findInstanceByNameInAssign(Node\Expr\Assign $assign, string $cla * * @throws ShouldNotHappenException * - * @return Node|null + * @return Node\Expr\Assign */ - public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): ?Node + public function replaceInstanceByNameInAssign(Node\Expr\Assign $assign, Node $replacement, string $class, string $name): Node\Expr\Assign { $node = $assign->expr; diff --git a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php index 3cf939eb..2168b796 100644 --- a/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php +++ b/src/Drupal8/Rector/Deprecation/FunctionalTestDefaultThemePropertyRector.php @@ -7,21 +7,20 @@ use Drupal\Tests\BrowserTestBase; use PhpParser\Builder\Property; use PhpParser\Node; -use PHPStan\Analyser\Scope; +use PHPStan\Php\PhpVersionFactory; use PHPStan\Type\ObjectType; use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory; use Rector\Exception\ShouldNotHappenException; use Rector\PhpParser\Node\Value\ValueResolver; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @changelog https://www.drupal.org/node/3083055 - * - * @see \DrupalRector\Tests\Rector\Class_\FunctionalTestDefaultThemePropertyRector\FunctionalTestDefaultThemePropertyRectorTest */ -final class FunctionalTestDefaultThemePropertyRector extends AbstractScopeAwareRector +final class FunctionalTestDefaultThemePropertyRector extends AbstractRector { /** * @var PhpDocInfoFactory @@ -33,10 +32,13 @@ final class FunctionalTestDefaultThemePropertyRector extends AbstractScopeAwareR */ private ValueResolver $valueResolver; - public function __construct(ValueResolver $valueResolver, PhpDocInfoFactory $phpDocInfoFactory) + private PhpVersionFactory $phpVersionFactory; + + public function __construct(ValueResolver $valueResolver, PhpDocInfoFactory $phpDocInfoFactory, PhpVersionFactory $phpVersionFactory) { $this->phpDocInfoFactory = $phpDocInfoFactory; $this->valueResolver = $valueResolver; + $this->phpVersionFactory = $phpVersionFactory; } public function getRuleDefinition(): RuleDefinition @@ -69,9 +71,8 @@ public function getNodeTypes(): array /** * @param Node\Stmt\Class_ $node */ - public function refactorWithScope(Node $node, Scope $scope): ?Node + public function refactor(Node $node): ?Node { - assert($node instanceof Node\Stmt\Class_); if ($node->isAbstract() || $node->isAnonymous()) { return null; } @@ -81,19 +82,29 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node return null; } - assert($type instanceof ObjectType); $browserTestBaseType = new ObjectType(BrowserTestBase::class); - if ($type->isSmallerThanOrEqual($browserTestBaseType)->yes()) { + if ($type->isSmallerThanOrEqual($browserTestBaseType, $this->phpVersionFactory->create())->yes()) { return null; } if ($type->isSuperTypeOf(new ObjectType(BrowserTestBase::class))->no()) { return null; } - $classReflection = $type->getClassReflection(); + + $classReflections = $type->getObjectClassReflections(); + $classReflection = null; + if (count($classReflections) !== 0) { + $classReflection = $classReflections[0]; + } + if ($classReflection === null || !$classReflection->hasNativeProperty('defaultTheme')) { - throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $type->getClassName())); + throw new ShouldNotHappenException(sprintf('Functional test class %s should have had a defaultTheme property but one not found.', $this->getName($node))); } + if (class_exists('Rector\PHPStan\ScopeFetcher')) { + $scope = ScopeFetcher::fetch($node); + } else { + $scope = $node->getAttribute('scope'); + } $defaultThemeProperty = $classReflection->getProperty('defaultTheme', $scope); assert($defaultThemeProperty instanceof \PHPStan\Reflection\Php\PhpPropertyReflection); diff --git a/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php b/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php index 677f5355..c5132e22 100644 --- a/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertFieldByIdRector.php @@ -5,6 +5,7 @@ namespace DrupalRector\Drupal9\Rector\Deprecation; use PhpParser\Node; +use PhpParser\Node\Expr\MethodCall; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -35,13 +36,13 @@ public function getRuleDefinition(): RuleDefinition public function getNodeTypes(): array { return [ - Node\Expr\MethodCall::class, + MethodCall::class, ]; } - public function refactor(Node $node) + public function refactor(Node $node): ?MethodCall { - assert($node instanceof Node\Expr\MethodCall); + assert($node instanceof MethodCall); if ($this->getName($node->name) !== 'assertFieldById') { return null; } diff --git a/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php b/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php index 69ca6451..68666dae 100644 --- a/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertFieldByNameRector.php @@ -37,7 +37,7 @@ public function getNodeTypes(): array ]; } - public function refactor(Node $node) + public function refactor(Node $node): ?Node\Expr\MethodCall { assert($node instanceof Node\Expr\MethodCall); if ($this->getName($node->name) !== 'assertFieldByName') { diff --git a/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php b/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php index 202a8b27..7d4d313a 100644 --- a/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertNoFieldByIdRector.php @@ -37,6 +37,9 @@ public function getNodeTypes(): array ]; } + /** + * @return Node|null + */ public function refactor(Node $node) { assert($node instanceof Node\Expr\MethodCall); diff --git a/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php b/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php index caabeefa..588b1785 100644 --- a/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php +++ b/src/Drupal9/Rector/Deprecation/AssertNoUniqueTextRector.php @@ -39,6 +39,9 @@ public function getNodeTypes(): array ]; } + /** + * @return Node[]|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); diff --git a/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php b/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php index e0d9ca33..a8043d94 100644 --- a/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php +++ b/src/Drupal9/Rector/Deprecation/ExtensionPathRector.php @@ -15,7 +15,7 @@ class ExtensionPathRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var \DrupalRector\Drupal9\Rector\ValueObject\ExtensionPathConfiguration[] + * @var ExtensionPathConfiguration[] */ private array $configuration; diff --git a/src/Drupal9/Rector/Deprecation/PassRector.php b/src/Drupal9/Rector/Deprecation/PassRector.php index 60b68900..b06368d7 100644 --- a/src/Drupal9/Rector/Deprecation/PassRector.php +++ b/src/Drupal9/Rector/Deprecation/PassRector.php @@ -7,6 +7,7 @@ use DrupalRector\Utility\GetDeclaringSourceTrait; use PhpParser\Node; use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -38,6 +39,11 @@ public function getNodeTypes(): array ]; } + /** + * @param Node $node + * + * @return Node|NodeTraverser::REMOVE_NODE|NodeVisitor::REMOVE_NODE|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); @@ -51,7 +57,12 @@ public function refactor(Node $node) } if ($this->getDeclaringSource($node->expr) === 'Drupal\KernelTests\AssertLegacyTrait') { - return NodeTraverser::REMOVE_NODE; + if (defined('\PhpParser\NodeVisitor::REMOVE_NODE')) { + return NodeVisitor::REMOVE_NODE; + } else { + /* @phpstan-ignore-next-line */ + return NodeTraverser::REMOVE_NODE; + } } return $node; diff --git a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php index 208f4ebf..a531bcfa 100644 --- a/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php +++ b/src/Drupal9/Rector/Deprecation/UiHelperTraitDrupalPostFormRector.php @@ -48,7 +48,7 @@ public function getNodeTypes(): array * * @throws ShouldNotHappenException * - * @return array + * @return array */ private function safeArgDestructure(Node\Expr\MethodCall $node): array { @@ -72,6 +72,9 @@ private function safeArgDestructure(Node\Expr\MethodCall $node): array throw new ShouldNotHappenException('Unexpected argument count for drupalPostForm'); } + /** + * @return Node[]|null + */ public function refactor(Node $node) { assert($node instanceof Node\Stmt\Expression); diff --git a/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php b/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php index 7206b85f..7b8116f2 100644 --- a/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php +++ b/src/Drupal9/Rector/Property/ProtectedStaticModulesPropertyRector.php @@ -53,9 +53,8 @@ public function getNodeTypes(): array /** * @param Node\Stmt\Property $node */ - public function refactor(Node $node): ?Node + public function refactor(Node $node): Node { - assert($node instanceof Node\Stmt\Property); if (!$this->isName($node, 'modules')) { return $node; } diff --git a/src/Rector/AbstractDrupalCoreRector.php b/src/Rector/AbstractDrupalCoreRector.php index 89ac7c5b..8edfb174 100644 --- a/src/Rector/AbstractDrupalCoreRector.php +++ b/src/Rector/AbstractDrupalCoreRector.php @@ -16,7 +16,7 @@ abstract class AbstractDrupalCoreRector extends AbstractRector implements ConfigurableRectorInterface { /** - * @var array|\DrupalRector\Contract\VersionedConfigurationInterface[] + * @var array|VersionedConfigurationInterface[] */ protected array $configuration = []; diff --git a/src/Rector/Deprecation/MethodToMethodWithCheckRector.php b/src/Rector/Deprecation/MethodToMethodWithCheckRector.php index 409feee4..9ab91198 100644 --- a/src/Rector/Deprecation/MethodToMethodWithCheckRector.php +++ b/src/Rector/Deprecation/MethodToMethodWithCheckRector.php @@ -117,8 +117,6 @@ public function refactor(Node $node): ?Node public function refactorNode(Node\Expr\MethodCall $node, ?Node\Stmt\Expression $statement, MethodToMethodWithCheckConfiguration $configuration): ?Node\Expr\MethodCall { - assert($node instanceof Node\Expr\MethodCall); - $callerType = $this->nodeTypeResolver->getType($node->var); $expectedType = new ObjectType($configuration->getClassName()); diff --git a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php index d142d486..e133f6a3 100644 --- a/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php +++ b/src/Rector/PHPUnit/ShouldCallParentMethodsRector.php @@ -5,12 +5,12 @@ namespace DrupalRector\Rector\PHPUnit; use PhpParser\Node; -use PHPStan\Analyser\Scope; -use Rector\Rector\AbstractScopeAwareRector; +use Rector\PHPStan\ScopeFetcher; +use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -class ShouldCallParentMethodsRector extends AbstractScopeAwareRector +class ShouldCallParentMethodsRector extends AbstractRector { public function getNodeTypes(): array { @@ -22,13 +22,17 @@ public function getNodeTypes(): array /** * @phpstan-param Node\Stmt\ClassMethod $node * - * @param Node $node - * @param Scope $scope + * @param Node $node * * @return Node|null */ - public function refactorWithScope(Node $node, Scope $scope) + public function refactor(Node $node) { + if (class_exists('Rector\PHPStan\ScopeFetcher')) { + $scope = ScopeFetcher::fetch($node); + } else { + $scope = $node->getAttribute('scope'); + } if ($scope->getClassReflection() === null) { return null; } diff --git a/src/Set/Drupal10SetList.php b/src/Set/Drupal10SetList.php index 724dd993..c0829218 100644 --- a/src/Set/Drupal10SetList.php +++ b/src/Set/Drupal10SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal10SetList implements SetListInterface +final class Drupal10SetList { public const DRUPAL_10 = __DIR__.'/../../config/drupal-10/drupal-10-all-deprecations.php'; public const DRUPAL_100 = __DIR__.'/../../config/drupal-10/drupal-10.0-deprecations.php'; diff --git a/src/Set/Drupal8SetList.php b/src/Set/Drupal8SetList.php index 17ced2b9..810190b7 100644 --- a/src/Set/Drupal8SetList.php +++ b/src/Set/Drupal8SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal8SetList implements SetListInterface +final class Drupal8SetList { public const DRUPAL_8 = __DIR__.'/../../config/drupal-8/drupal-8-all-deprecations.php'; public const DRUPAL_80 = __DIR__.'/../../config/drupal-8/drupal-8.0-deprecations.php'; diff --git a/src/Set/Drupal9SetList.php b/src/Set/Drupal9SetList.php index 1141640f..b6397ec9 100644 --- a/src/Set/Drupal9SetList.php +++ b/src/Set/Drupal9SetList.php @@ -4,9 +4,7 @@ namespace DrupalRector\Set; -use Rector\Set\Contract\SetListInterface; - -final class Drupal9SetList implements SetListInterface +final class Drupal9SetList { public const DRUPAL_9 = __DIR__.'/../../config/drupal-9/drupal-9-all-deprecations.php'; public const DRUPAL_90 = __DIR__.'/../../config/drupal-9/drupal-9.0-deprecations.php';