diff --git a/.github/workflows/functional_test__rector_examples.yml b/.github/workflows/functional_test__rector_examples.yml index dc4657ff..a2fbfb73 100644 --- a/.github/workflows/functional_test__rector_examples.yml +++ b/.github/workflows/functional_test__rector_examples.yml @@ -13,24 +13,18 @@ on: jobs: run_functional_test: - name: Functional Test | PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal }}" + name: Functional | PHP ${{ matrix.php-version }} | Drupal ${{ matrix.drupal }}" strategy: fail-fast: false matrix: include: - - php-version: "7.4" - drupal: "^8.9" - fixture: "d8" - - php-version: "7.4" - drupal: "^9.2" - fixture: "d9" - php-version: "8.0" drupal: "^9.2" fixture: "d9" - php-version: "8.1" drupal: "^10.0" fixture: "d10" - - php-version: "8.2" + - php-version: "8.3" drupal: "^10.0" fixture: "d10" runs-on: ubuntu-latest diff --git a/composer.json b/composer.json index 232ed286..537f672b 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,7 @@ "keywords": [ "code style", "rector", - "drupal 8", - "drupal 9", + "drupal", "ast" ], "require": { diff --git a/config/drupal-phpunit-bootstrap-file.php b/config/drupal-phpunit-bootstrap-file.php index b49f159b..3bb781d0 100644 --- a/config/drupal-phpunit-bootstrap-file.php +++ b/config/drupal-phpunit-bootstrap-file.php @@ -6,12 +6,17 @@ * This fixes Drupal testing namespace autoloading and PHPUnit compatibility. */ -use DrupalFinder\DrupalFinder; use Rector\Core\Autoloading\BootstrapFilesIncluder; use Rector\Core\Exception\ShouldNotHappenException; -$drupalFinder = new DrupalFinder(); -$drupalFinder->locateRoot(__DIR__); + +if (class_exists('DrupalFinder\DrupalFinderComposerRuntime')) { + $drupalFinder = new DrupalFinder\DrupalFinderComposerRuntime(); +} else { + $drupalFinder = new DrupalFinder\DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); +} + $drupalRoot = $drupalFinder->getDrupalRoot(); $drupalVendorRoot = $drupalFinder->getVendorDir(); diff --git a/docs/rules_overview.md b/docs/rules_overview.md index ccf94f13..1149b25f 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,10 +1,10 @@ -# 54 Rules Overview +# 55 Rules Overview
## Categories -- [Drupal10](#drupal10) (3) +- [Drupal10](#drupal10) (4) - [Drupal8](#drupal8) (18) @@ -72,6 +72,21 @@ Fixes deprecated `system_time_zones()` calls
+### VersionedFunctionToServiceRector + +Fixes deprecated function to service calls, used in Drupal 8 and 9 deprecations + +:wrench: **configure it!** + +- class: [`DrupalRector\Drupal10\Rector\Deprecation\VersionedFunctionToServiceRector`](../src/Drupal10/Rector/Deprecation/VersionedFunctionToServiceRector.php) + +```diff +-_drupal_flush_css_js(); ++\Drupal::service('asset.query_string')->reset(); +``` + +
+ ### WatchdogExceptionRector Fixes deprecated watchdog_exception('update', `$exception)` calls diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index e7a5893b..38ca9036 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,5 +1,15 @@ parameters: ignoreErrors: + - + 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 @@ -35,6 +45,34 @@ parameters: 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 @@ -117,3 +155,27 @@ parameters: """ count: 1 path: src/Drupal9/Rector/Deprecation/PassRector.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$# + """ + count: 1 + path: src/Set/Drupal10SetList.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$# + """ + count: 1 + path: src/Set/Drupal8SetList.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$# + """ + count: 1 + path: src/Set/Drupal9SetList.php diff --git a/rector.php b/rector.php index 85d0b687..8d140f13 100644 --- a/rector.php +++ b/rector.php @@ -2,7 +2,6 @@ declare(strict_types=1); -use DrupalFinder\DrupalFinder; use DrupalRector\Set\Drupal10SetList; use DrupalRector\Set\Drupal8SetList; use DrupalRector\Set\Drupal9SetList; @@ -12,14 +11,20 @@ // Adjust the set lists to be more granular to your Drupal requirements. // @todo find out how to only load the relevant rector rules. // Should we try and load \Drupal::VERSION and check? + // new possible option with ComposerTriggeredSet + // https://github.com/rectorphp/rector-src/blob/b5a5739b7d7dde621053adff113449860ed5331f/src/Set/ValueObject/ComposerTriggeredSet.php $rectorConfig->sets([ Drupal8SetList::DRUPAL_8, Drupal9SetList::DRUPAL_9, Drupal10SetList::DRUPAL_10, ]); - $drupalFinder = new DrupalFinder(); - $drupalFinder->locateRoot(__DIR__); + if (class_exists('DrupalFinder\DrupalFinderComposerRuntime')) { + $drupalFinder = new DrupalFinder\DrupalFinderComposerRuntime(); + } else { + $drupalFinder = new DrupalFinder\DrupalFinder(); + $drupalFinder->locateRoot(__DIR__); + } $drupalRoot = $drupalFinder->getDrupalRoot(); $rectorConfig->autoloadPaths([ $drupalRoot . '/core', diff --git a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php index 9b26d5b6..9cfb53b5 100644 --- a/src/Drupal8/Rector/Deprecation/EntityManagerRector.php +++ b/src/Drupal8/Rector/Deprecation/EntityManagerRector.php @@ -45,10 +45,8 @@ final class EntityManagerRector extends AbstractRector */ private AddCommentService $commentService; - public function __construct( - ParentClassScopeResolver $parentClassScopeResolver, - AddCommentService $commentService - ) { + public function __construct(ParentClassScopeResolver $parentClassScopeResolver, AddCommentService $commentService) + { $this->parentClassScopeResolver = $parentClassScopeResolver; $this->commentService = $commentService; }