diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 3279867..8b478d0 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -68,6 +68,8 @@ use Rector\Transform\ValueObject\MethodCallToPropertyFetch; use Neos\Rector\ContentRepository90\Rules\FusionNodeHiddenAfterDateTimeRector; use Neos\Rector\ContentRepository90\Rules\FusionNodeHiddenBeforeDateTimeRector; +use Neos\Rector\Generic\Rules\FusionReplacePrototypeNameRector; +use Neos\Rector\Generic\ValueObject\FusionPrototypeNameReplacement; return static function (RectorConfig $rectorConfig): void { // Register FusionFileProcessor. All Fusion Rectors will be auto-registered at this processor. @@ -97,6 +99,13 @@ 'Neos\ContentRepository\Domain\Model\Workspace' => \Neos\ContentRepository\Core\Projection\Workspace\Workspace::class, ]); + $rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [ + new FusionPrototypeNameReplacement('Neos.Fusion:Array' , 'Neos.Fusion:Join'), + new FusionPrototypeNameReplacement('Neos.Fusion:RawArray' , 'Neos.Fusion:DataStructure'), + new FusionPrototypeNameReplacement('Neos.Fusion:Collection' , 'Neos.Fusion:Loop'), + new FusionPrototypeNameReplacement('Neos.Fusion:RawCollection', 'Neos.Fusion:Map'), + ]); + /** @var $methodCallToPropertyFetches MethodCallToPropertyFetch[] */ $methodCallToPropertyFetches = []; diff --git a/src/Generic/Rules/FusionReplacePrototypeNameRector.php b/src/Generic/Rules/FusionReplacePrototypeNameRector.php new file mode 100644 index 0000000..89de0fc --- /dev/null +++ b/src/Generic/Rules/FusionReplacePrototypeNameRector.php @@ -0,0 +1,45 @@ +fusionPrototypeNameReplacements as $fusionPrototypeNameReplacement) { + $pattern = '/(^|[=\s\(<\/])(' .$fusionPrototypeNameReplacement->oldName. ')([\s\{\)\/>]|$)/'; + $replacement = '$1'.$fusionPrototypeNameReplacement->newName.'$3'; + $fileContent = preg_replace($pattern, $replacement, $fileContent); + } + + return $fileContent; + } + + /** + * @param FusionNodePropertyPathToWarningComment[] $configuration + */ + public function configure(array $configuration): void + { + Assert::allIsAOf($configuration, FusionPrototypeNameReplacement::class); + $this->fusionPrototypeNameReplacements = $configuration; + } +} diff --git a/src/Generic/ValueObject/FusionPrototypeNameReplacement.php b/src/Generic/ValueObject/FusionPrototypeNameReplacement.php new file mode 100644 index 0000000..dec74a4 --- /dev/null +++ b/src/Generic/ValueObject/FusionPrototypeNameReplacement.php @@ -0,0 +1,13 @@ + + + + ` + } +} +----- +prototype(Neos.Neos:SomethingNew) < prototype(Neos.Neos:NewRaw) { + + raw = Neos.Neos:NewRaw + rawer = Neos.Neos:Rawer + + renderer = Neos.Neos:NewRaw { + + old = Neos.Neos:SomethingNew + + renderer = afx` + + + + ` + } +} diff --git a/tests/Generic/Rules/FusionPrototypeNameReplacement/FusionPrototypeNameReplacementTest.php b/tests/Generic/Rules/FusionPrototypeNameReplacement/FusionPrototypeNameReplacementTest.php new file mode 100644 index 0000000..5ed741f --- /dev/null +++ b/tests/Generic/Rules/FusionPrototypeNameReplacement/FusionPrototypeNameReplacementTest.php @@ -0,0 +1,31 @@ +doTestFile($fileInfo); + } + + /** + * @return \Iterator + */ + public function provideData(): \Iterator + { + return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture', '*.fusion.inc'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php b/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php new file mode 100644 index 0000000..61b9ebe --- /dev/null +++ b/tests/Generic/Rules/FusionPrototypeNameReplacement/config/configured_rule.php @@ -0,0 +1,23 @@ +services(); + $services->defaults() + ->public() + ->autowire() + ->autoconfigure(); + $services->set(FusionFileProcessor::class); + $rectorConfig->disableParallel(); // does not work for fusion files - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688 + + $rectorConfig->ruleWithConfiguration(FusionReplacePrototypeNameRector::class, [ + new FusionPrototypeNameReplacement('Neos.Neos:Raw', 'Neos.Neos:NewRaw'), + new FusionPrototypeNameReplacement('Neos.Neos:SomethingOld', 'Neos.Neos:SomethingNew'), + ]); +};