diff --git a/config/drupal-9/drupal-9.1-deprecations.php b/config/drupal-9/drupal-9.1-deprecations.php index bbf95cba..d9ef64f8 100644 --- a/config/drupal-9/drupal-9.1-deprecations.php +++ b/config/drupal-9/drupal-9.1-deprecations.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector; use DrupalRector\Rector\Deprecation\AssertCacheTagRector; use DrupalRector\Rector\Deprecation\AssertElementNotPresentRector; use DrupalRector\Rector\Deprecation\AssertElementPresentRector; @@ -182,4 +183,5 @@ $rectorConfig->rule(GetRawContentRector::class); $rectorConfig->rule(GetAllOptionsRector::class); $rectorConfig->rule(UserPasswordRector::class); + $rectorConfig->rule(SymfonyCmfRouteObjectInterfaceConstantsRector::class); }; diff --git a/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector.php b/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector.php new file mode 100644 index 00000000..fb704538 --- /dev/null +++ b/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector.php @@ -0,0 +1,69 @@ +> + */ + public function getNodeTypes(): array + { + return [\PhpParser\Node\Expr\ClassConstFetch::class]; + } + + /** + * @param \PhpParser\Node\Expr\ClassConstFetch $node + */ + public function refactor(Node $node): ?Node + { + $cmfRouteObjectInterfaceType = new ObjectType(\Symfony\Cmf\Component\Routing\RouteObjectInterface::class); + if (!$this->isObjectType($node->class, $cmfRouteObjectInterfaceType)) { + return $node; + } + + $node->class = new FullyQualified(\Drupal\Core\Routing\RouteObjectInterface::class); + return $node; + } +} diff --git a/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/Fixture/some_class.php.inc b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/Fixture/some_class.php.inc new file mode 100644 index 00000000..809d1981 --- /dev/null +++ b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/Fixture/some_class.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/SymfonyCmfRouteObjectInterfaceConstantsRectorTest.php b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/SymfonyCmfRouteObjectInterfaceConstantsRectorTest.php new file mode 100644 index 00000000..65a4c1a1 --- /dev/null +++ b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/SymfonyCmfRouteObjectInterfaceConstantsRectorTest.php @@ -0,0 +1,31 @@ +doTestFileInfo($fileInfo); + } + + /** + * @return \Iterator<\Symplify\SmartFileSystem\SmartFileInfo> + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/config/configured_rule.php b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/config/configured_rule.php new file mode 100644 index 00000000..14bb8f65 --- /dev/null +++ b/tests/src/Rector/ConstFetch/SymfonyCmfRouteObjectInterfaceConstantsRector/config/configured_rule.php @@ -0,0 +1,9 @@ +rule(\DrupalRector\Rector\ConstFetch\SymfonyCmfRouteObjectInterfaceConstantsRector::class); +};