diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index a9c40ce..187d212 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -72,6 +72,7 @@ use Neos\Rector\Generic\Rules\FusionReplacePrototypeNameRector; use Neos\Rector\Generic\ValueObject\FusionPrototypeNameReplacement; use Neos\Rector\Generic\ValueObject\FusionPrototypeNameAddComment; +use Neos\Rector\ContentRepository90\Rules\ContentRepositoryUtilityRenderValidNodeNameRector; return static function (RectorConfig $rectorConfig): void { // Register FusionFileProcessor. All Fusion Rectors will be auto-registered at this processor. @@ -394,12 +395,7 @@ new FusionPrototypeNameAddComment('Neos.Fusion:Attributes', 'TODO 9.0 migration: Neos.Fusion:Attributes has been removed without a replacement. You need to replace it by the property attributes in Neos.Fusion:Tag') ]); - $rectorConfig->ruleWithConfiguration(RenameStaticMethodRector::class, [new RenameStaticMethod( - \Neos\ContentRepository\Utility::class, - 'renderValidNodeName', - \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class, - 'transliterateFromString' - )]); + $rectorConfig->rule(ContentRepositoryUtilityRenderValidNodeNameRector::class); /** * SPECIAL rules diff --git a/src/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector.php b/src/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector.php new file mode 100644 index 0000000..4cffb5c --- /dev/null +++ b/src/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector.php @@ -0,0 +1,53 @@ +value.', [new CodeSample('\Neos\ContentRepository\Utility::renderValidNodeName(\'foo\');', '\Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString(\'foo\')->value;')]); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [StaticCall::class]; + } + + /** + * @param StaticCall $node + */ + public function refactor(Node $node): ?Node + { + if (!$this->isName($node->name, 'renderValidNodeName')) { + return null; + } + if (!$this->isObjectType($node->class, new ObjectType(\Neos\ContentRepository\Utility::class))) { + return null; + } + $staticCall = $this->rename($node, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class, 'fromString'); + return $this->nodeFactory->createPropertyFetch($staticCall, 'value'); + } + + private function rename(StaticCall $staticCall, $newClassName, $newMethodName): StaticCall + { + $staticCall->name = new Identifier($newMethodName); + $staticCall->class = new FullyQualified($newClassName); + return $staticCall; + } +} diff --git a/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/ContentRepositoryUtilityRenderValidNodeNameTest.php b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/ContentRepositoryUtilityRenderValidNodeNameTest.php new file mode 100644 index 0000000..6fd3052 --- /dev/null +++ b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/ContentRepositoryUtilityRenderValidNodeNameTest.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/Fixture/some_class.php.inc new file mode 100644 index 0000000..806acfa --- /dev/null +++ b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/Fixture/some_class.php.inc @@ -0,0 +1,29 @@ + +----- +value; + $liveNodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString('live')->value; + } +} + +?> diff --git a/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/config/configured_rule.php b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/config/configured_rule.php new file mode 100644 index 0000000..1a3c7b9 --- /dev/null +++ b/tests/ContentRepository90/Rules/ContentRepositoryUtilityRenderValidNodeNameRector/config/configured_rule.php @@ -0,0 +1,12 @@ +rule(\Neos\Rector\ContentRepository90\Rules\ContentRepositoryUtilityRenderValidNodeNameRector::class); +};