diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 5025602..7d73fad 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -45,6 +45,8 @@ use Rector\Transform\ValueObject\MethodCallToPropertyFetch; use Neos\Rector\ContentRepository90\Rules\WorkspaceGetNameRector; use Neos\Rector\ContentRepository90\Rules\NodeGetIdentifierRector; +use Neos\Rector\ContentRepository90\Rules\FusionNodeTypeNameRector; +use Neos\Rector\ContentRepository90\Rules\NodeTypeGetNameRector; return static function (RectorConfig $rectorConfig): void { // Register FusionFileProcessor. All Fusion Rectors will be auto-registered at this processor. @@ -215,6 +217,13 @@ // hasProperty() ** (included/compatible in old NodeInterface) // getLabel() ** (included/compatible in old NodeInterface) + /** + * Neos\ContentRepository\Core\NodeType\NodeType + */ + // getName() + $rectorConfig->rule(rectorClass: FusionNodeTypeNameRector::class); + $rectorConfig->rule(rectorClass: NodeTypeGetNameRector::class); + /** * Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface */ diff --git a/src/ContentRepository90/Rules/FusionNodeTypeNameRector.php b/src/ContentRepository90/Rules/FusionNodeTypeNameRector.php new file mode 100644 index 0000000..11bf397 --- /dev/null +++ b/src/ContentRepository90/Rules/FusionNodeTypeNameRector.php @@ -0,0 +1,33 @@ +process(fn(string $eelExpression) => preg_replace( + '/(node|documentNode|site)\.nodeType\.name/', + '$1.nodeTypeName.value', + $eelExpression + )) + ->addCommentsIfRegexMatches( + '/\.nodeType.name/', + '// TODO 9.0 migration: Line %LINE: You may need to rewrite "VARIABLE.nodeType.name" to "VARIABLE.nodeTypeName.value". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.' + )->getProcessedContent(); + } +} diff --git a/src/ContentRepository90/Rules/NodeTypeGetNameRector.php b/src/ContentRepository90/Rules/NodeTypeGetNameRector.php new file mode 100644 index 0000000..0deac54 --- /dev/null +++ b/src/ContentRepository90/Rules/NodeTypeGetNameRector.php @@ -0,0 +1,53 @@ +> + */ + public function getNodeTypes(): array + { + return [\PhpParser\Node\Expr\MethodCall::class]; + } + + /** + * @param \PhpParser\Node\Expr\MethodCall $node + */ + public function refactor(Node $node): ?Node + { + assert($node instanceof Node\Expr\MethodCall); + + if (!$this->isObjectType($node->var, new ObjectType('Neos\ContentRepository\Core\NodeType\NodeType'))) { + return null; + } + if (!$this->isName($node->name, 'getName')) { + return null; + } + + $propertyFetchAggregateId = $this->nodeFactory->createPropertyFetch($node->var, 'name'); + return $this->nodeFactory->createPropertyFetch($propertyFetchAggregateId, 'value'); + } +} diff --git a/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/Fixture/some_file.fusion.inc b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/Fixture/some_file.fusion.inc new file mode 100644 index 0000000..23010be --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/Fixture/some_file.fusion.inc @@ -0,0 +1,36 @@ +prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { + +renderer = Neos.Fusion:Component { + +# +# pass down props +# +attributes = ${node.nodeType.name || documentNode.nodeType.name} +renderer = afx` + +` +} +} +----- +// TODO 9.0 migration: Line 13: You may need to rewrite "VARIABLE.nodeType.name" to "VARIABLE.nodeTypeName.value". We did not auto-apply this migration because we cannot be sure whether the variable is a Node. +prototype(Neos.Fusion.Form:Checkbox) < prototype(Neos.Fusion.Form:Component.Field) { + +renderer = Neos.Fusion:Component { + +# +# pass down props +# +attributes = ${node.nodeTypeName.value || documentNode.nodeTypeName.value} +renderer = afx` + +` +} +} diff --git a/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/FusionNodeTypeNameRectorTest.php b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/FusionNodeTypeNameRectorTest.php new file mode 100644 index 0000000..c5a7d79 --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/FusionNodeTypeNameRectorTest.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/ContentRepository90/Rules/FusionNodeTypeNameRector/config/configured_rule.php b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/config/configured_rule.php new file mode 100644 index 0000000..6453e6b --- /dev/null +++ b/tests/ContentRepository90/Rules/FusionNodeTypeNameRector/config/configured_rule.php @@ -0,0 +1,19 @@ +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->rule(FusionNodeTypeNameRector::class); +}; diff --git a/tests/Rules/NodeTypeGetNameRector/Fixture/all.php.inc b/tests/Rules/NodeTypeGetNameRector/Fixture/all.php.inc new file mode 100644 index 0000000..b51824e --- /dev/null +++ b/tests/Rules/NodeTypeGetNameRector/Fixture/all.php.inc @@ -0,0 +1,27 @@ +getName(); + } +} + +?> +----- +name->value; + } +} + +?> diff --git a/tests/Rules/NodeTypeGetNameRector/NodeTypeGetNameRectorTest.php b/tests/Rules/NodeTypeGetNameRector/NodeTypeGetNameRectorTest.php new file mode 100644 index 0000000..f56bda0 --- /dev/null +++ b/tests/Rules/NodeTypeGetNameRector/NodeTypeGetNameRectorTest.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/Rules/NodeTypeGetNameRector/config/configured_rule.php b/tests/Rules/NodeTypeGetNameRector/config/configured_rule.php new file mode 100644 index 0000000..e36b0ea --- /dev/null +++ b/tests/Rules/NodeTypeGetNameRector/config/configured_rule.php @@ -0,0 +1,11 @@ +rule(NodeTypeGetNameRector::class); +};