From ee4abe5be49106aac82f94984cb7c136a6aee48b Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 18 Nov 2024 17:32:26 +0100 Subject: [PATCH 1/4] FEATURE: Improve Node and Node interfaces rewrites --- config/set/contentrepository-90.php | 18 ++- src/ContentRepository90/Legacy/Node.php | 13 ++ .../Legacy/NodeInterface.php | 13 ++ .../Legacy/NodeLegacyStub.php | 29 +++++ .../Legacy/TraversableNodeInterface.php | 13 ++ .../Legacy/TraversableNodes.php | 27 +++++ .../Rules/NodeGetNodeTypeGetNameRector.php | 72 +++++++++++ .../Rules/NodeGetNodeTypeRector.php | 69 +++++++++++ .../Rules/NodeGetPropertyNamesRector.php | 62 ++++++++++ ...NodeTypeAllowsGrandchildNodeTypeRector.php | 13 +- ...NodeTypeGetAutoCreatedChildNodesRector.php | 12 +- ...ypeGetTypeOfAutoCreatedChildNodeRector.php | 32 +++-- .../Fixture/some_class.php.inc | 33 +++++ .../NodeGetNodeTypeGetNameRectorTest.php | 31 +++++ .../config/configured_rule.php | 10 ++ .../Fixture/some_class.php.inc} | 6 +- .../NodeGetNodeTypeRectorTest.php | 31 +++++ .../config/configured_rule.php | 11 ++ .../Fixture/some_class.php.inc | 27 +++++ .../NodeGetPropertyNamesRectorTest.php | 31 +++++ .../config/configured_rule.php | 10 ++ .../Fixture/some_class.php.inc | 2 +- .../Fixture/some_class.php.inc | 8 +- .../Fixture/some_class3.php.inc | 33 ----- .../Fixture/some_class4.php.inc | 31 ----- .../Fixture/some_class5.php.inc | 35 ------ .../{some_class.php.inc => default.php.inc} | 3 +- .../Fixture/some_class2.php.inc | 35 ------ .../Fixture/some_class3.php.inc | 37 ------ .../Fixture/Node/node-get-child.php.inc | 93 ++++++++++++++ .../Fixture/Node/node-get-parent.php.inc | 71 +++++++++++ .../Fixture/Node/node-hidden-in-index.php.inc | 31 +++++ .../Fixture/Node/node-name.php.inc | 33 +++++ .../node-nodetype-and-nodetypename.php.inc | 113 ++++++++++++++++++ .../Fixture/Node/node-properties.php.inc | 45 +++++++ 35 files changed, 926 insertions(+), 207 deletions(-) create mode 100644 src/ContentRepository90/Legacy/Node.php create mode 100644 src/ContentRepository90/Legacy/NodeInterface.php create mode 100644 src/ContentRepository90/Legacy/TraversableNodeInterface.php create mode 100644 src/ContentRepository90/Legacy/TraversableNodes.php create mode 100644 src/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector.php create mode 100644 src/ContentRepository90/Rules/NodeGetNodeTypeRector.php create mode 100644 src/ContentRepository90/Rules/NodeGetPropertyNamesRector.php create mode 100644 tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/Fixture/some_class.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/NodeGetNodeTypeGetNameRectorTest.php create mode 100644 tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/config/configured_rule.php rename tests/ContentRepository90/Rules/{NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class2.php.inc => NodeGetNodeTypeRector/Fixture/some_class.php.inc} (64%) create mode 100644 tests/ContentRepository90/Rules/NodeGetNodeTypeRector/NodeGetNodeTypeRectorTest.php create mode 100644 tests/ContentRepository90/Rules/NodeGetNodeTypeRector/config/configured_rule.php create mode 100644 tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/Fixture/some_class.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/NodeGetPropertyNamesRectorTest.php create mode 100644 tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/config/configured_rule.php delete mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class3.php.inc delete mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class4.php.inc delete mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class5.php.inc rename tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/{some_class.php.inc => default.php.inc} (89%) delete mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class2.php.inc delete mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class3.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-get-child.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-get-parent.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-hidden-in-index.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-name.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc create mode 100644 tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index e946f79..4c556d7 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -43,8 +43,11 @@ use Neos\Rector\ContentRepository90\Rules\NodeGetDepthRector; use Neos\Rector\ContentRepository90\Rules\NodeGetDimensionsRector; use Neos\Rector\ContentRepository90\Rules\NodeGetIdentifierRector; +use Neos\Rector\ContentRepository90\Rules\NodeGetNodeTypeGetNameRector; +use Neos\Rector\ContentRepository90\Rules\NodeGetNodeTypeRector; use Neos\Rector\ContentRepository90\Rules\NodeGetParentRector; use Neos\Rector\ContentRepository90\Rules\NodeGetPathRector; +use Neos\Rector\ContentRepository90\Rules\NodeGetPropertyNamesRector; use Neos\Rector\ContentRepository90\Rules\NodeIsHiddenInIndexRector; use Neos\Rector\ContentRepository90\Rules\NodeIsHiddenRector; use Neos\Rector\ContentRepository90\Rules\NodeLabelGeneratorRector; @@ -89,12 +92,14 @@ $services->set(\Neos\Rector\Core\YamlProcessing\YamlFileProcessor::class); $rectorConfig->disableParallel(); // parallel does not work for non-PHP-Files, so we need to disable it - see https://github.com/rectorphp/rector-src/pull/2597#issuecomment-1190120688 + $rectorConfig->autoloadPaths([__DIR__ . '/../../src/ContentRepository90/Legacy']); $rectorConfig->ruleWithConfiguration(RenameClassRector::class, [ \Neos\ContentRepository\Domain\Model\Node::class => NodeLegacyStub::class, \Neos\ContentRepository\Domain\Model\NodeInterface::class => NodeLegacyStub::class, \Neos\ContentRepository\Domain\Projection\Content\NodeInterface::class => NodeLegacyStub::class, \Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface::class => NodeLegacyStub::class, + \Neos\ContentRepository\Domain\Projection\Content\TraversableNodes::class => \Neos\ContentRepository\Core\Projection\ContentGraph\Nodes::class, \Neos\ContentRepository\Domain\Service\Context::class => LegacyContextStub::class, @@ -136,6 +141,7 @@ * Neos\ContentRepository\Domain\Model\NodeInterface */ // setName + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setName', '!! Node::setName() is not supported by the new CR. Use the "ChangeNodeAggregateName" command to change the node name.'); // getName $methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getName', 'nodeName'); $fusionFlowQueryPropertyToComments[] = new FusionFlowQueryNodePropertyToWarningComment('_name', 'Line %LINE: !! You very likely need to rewrite "q(VARIABLE).property("_name")" to "VARIABLE.nodeName". We did not auto-apply this migration because we cannot be sure whether the variable is a Node.'); @@ -143,12 +149,15 @@ $rectorConfig->rule(FusionNodeLabelRector::class); $rectorConfig->rule(NodeLabelGeneratorRector::class); // setProperty + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setProperty', '!! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to change property values.'); // hasProperty -> compatible with ES CR Node (nothing to do) // getProperty -> compatible with ES CR Node (nothing to do) // removeProperty + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'removeProperty', '!! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values.'); // getProperties -> PropertyCollectionInterface $methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getProperties', 'properties'); // getPropertyNames + $rectorConfig->rule(NodeGetPropertyNamesRector::class); // setContentObject -> DEPRECATED / NON-FUNCTIONAL $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setContentObject', '!! Node::setContentObject() is not supported by the new CR. Referencing objects can be done by storing them in Node::properties (and the serialization/deserialization is extensible).'); // getContentObject -> DEPRECATED / NON-FUNCTIONAL @@ -156,7 +165,11 @@ // unsetContentObject -> DEPRECATED / NON-FUNCTIONAL $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'unsetContentObject', '!! Node::unsetContentObject() is not supported by the new CR. Referencing objects can be done by storing them in Node::properties (and the serialization/deserialization is extensible).'); // setNodeType + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setNodeType', '!! Node::setNodeType() is not supported by the new CR. Use the "ChangeNodeAggregateType" command to change nodetype.'); // getNodeType: NodeType + // PHP: shortcut to Node->nodeTypeName->value + $rectorConfig->rule(NodeGetNodeTypeGetNameRector::class); + $rectorConfig->rule(NodeGetNodeTypeRector::class); // Fusion: node.nodeType -> Neos.Node.nodeType(node) // Fusion: node.nodeType.name -> node.nodeTypeName $rectorConfig->rule(FusionNodeNodeTypeRector::class); @@ -176,6 +189,7 @@ $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getHiddenAfterDateTime', '!! Node::getHiddenAfterDateTime() is not supported by the new CR. Timed publishing will be implemented not on the read model, but by dispatching commands at a given time.'); $rectorConfig->rule(FusionNodeHiddenAfterDateTimeRector::class); // setHiddenInIndex + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setHiddenInIndex', '!! Node::setHiddenInIndex() is not supported by the new CR. Use the "SetNodeProperties" command to change the property value for "hiddenInMenu".'); // isHiddenInIndex $rectorConfig->rule(NodeIsHiddenInIndexRector::class); // Fusion: .hiddenInIndex -> node.properties._hiddenInIndex @@ -462,7 +476,9 @@ // We can only add one rule per class name. As workaround, we need to alias the RenameClassRector, so we are able to // add this rule twice. - class_alias(RenameClassRector::class, \Alias\RenameClassRectorLegacy::class); + if (!class_exists(\Alias\RenameClassRectorLegacy::class)){ + class_alias(RenameClassRector::class, \Alias\RenameClassRectorLegacy::class); + } $rectorConfig->ruleWithConfiguration(\Alias\RenameClassRectorLegacy::class, [ NodeLegacyStub::class => Node::class, ]); diff --git a/src/ContentRepository90/Legacy/Node.php b/src/ContentRepository90/Legacy/Node.php new file mode 100644 index 0000000..c9a225c --- /dev/null +++ b/src/ContentRepository90/Legacy/Node.php @@ -0,0 +1,13 @@ + + * @deprecated + */ +class TraversableNodes implements \IteratorAggregate, \Countable +{ + + /** + * @return TraversableNodeInterface[]|\ArrayIterator + */ + public function getIterator(): Traversable + { + return new \ArrayIterator(); + } + + public function count(): int + { + } +} diff --git a/src/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector.php b/src/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector.php new file mode 100644 index 0000000..d341321 --- /dev/null +++ b/src/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector.php @@ -0,0 +1,72 @@ +getName()" will be rewritten', __CLASS__); + } + + /** + * @return array> + */ + 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::class))) { + return null; + } + if (!$this->isName($node->name, 'getName')) { + return null; + } + + if (!$node->var instanceof Node\Expr\MethodCall) { + return null; + } + + $nodeTypeVar = $node->var; + + if (!$this->isObjectType($nodeTypeVar->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) { + return null; + } + + if (!$this->isName($nodeTypeVar->name, 'getNodeType')) { + return null; + } + + return + $this->nodeFactory->createPropertyFetch( + $this->nodeFactory->createPropertyFetch( + $node->var->var, + 'nodeTypeName' + ), 'value' + ); + } +} diff --git a/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php b/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php new file mode 100644 index 0000000..eac3a96 --- /dev/null +++ b/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php @@ -0,0 +1,69 @@ +> + */ + 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\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) { + return null; + } + + if (!$this->isName($node->name, 'getNodeType')) { + return null; + } + + $this->nodesToAddCollector->addNodesBeforeNode( + [ + self::withTodoComment( + 'Make this code aware of multiple Content Repositories.', + self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))), + ) + ], + $node + ); + + return + $this->nodeFactory->createMethodCall( + $this->contentRepository_getNodeTypeManager() + , 'getNodeType', + [ + $this->nodeFactory->createPropertyFetch($node->var, 'nodeTypeName') + ]); + } +} diff --git a/src/ContentRepository90/Rules/NodeGetPropertyNamesRector.php b/src/ContentRepository90/Rules/NodeGetPropertyNamesRector.php new file mode 100644 index 0000000..c7771a3 --- /dev/null +++ b/src/ContentRepository90/Rules/NodeGetPropertyNamesRector.php @@ -0,0 +1,62 @@ +allowsGrandchildNodeType($parentNodeName, $nodeType)" will be rewritten.', __CLASS__); + } + + /** + * @return array> + */ + public function getNodeTypes(): array + { + return [Node\Expr\MethodCall::class]; + } + + /** + * @param Node\Expr\MethodCall $node + */ + public function refactor(Node $node): ?Node + { + assert($node instanceof Node\Expr\MethodCall); + + if (!$this->isObjectType($node->var, new ObjectType(NodeLegacyStub::class))) { + return null; + } + + if (!$this->isName($node->name, 'getPropertyNames')) { + return null; + } + + return + $this->nodeFactory->createFuncCall('array_keys', [ + $this->nodeFactory->createFuncCall('iterator_to_array', [ + $this->nodeFactory->createPropertyFetch($node->var, 'properties'), + ]), + ]); + } +} diff --git a/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php b/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php index 298973e..c16cfdb 100644 --- a/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php +++ b/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php @@ -4,14 +4,13 @@ namespace Neos\Rector\ContentRepository90\Rules; +use Neos\ContentRepository\Core\NodeType\NodeType; use Neos\Rector\Utility\CodeSampleLoader; use PhpParser\Node; use PHPStan\Type\ObjectType; use Rector\Core\Rector\AbstractRector; use Rector\PostRector\Collector\NodesToAddCollector; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -use Neos\ContentRepository\Core\NodeType\NodeType; -use PhpParser\NodeDumper; final class NodeTypeAllowsGrandchildNodeTypeRector extends AbstractRector { @@ -64,7 +63,10 @@ public function refactor(Node $node): ?Node $this->contentRepository_getNodeTypeManager(), 'isNodeTypeAllowedAsChildToTetheredNode', [ - $node->var, + $this->nodeFactory->createPropertyFetch( + $node->var, + 'name' + ), $this->nodeFactory->createStaticCall( \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class, 'fromString', @@ -72,7 +74,10 @@ public function refactor(Node $node): ?Node $node->args[0] ] ), - $node->args[1] + $this->nodeFactory->createPropertyFetch( + $node->args[1]->value, + 'name' + ) ] ); } diff --git a/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php b/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php index 36eb25b..84077d6 100644 --- a/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php +++ b/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php @@ -50,18 +50,16 @@ public function refactor(Node $node) : ?Node $this->nodesToAddCollector->addNodesBeforeNode( [ - self::withTodoComment( - 'Make this code aware of multiple Content Repositories.', - self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))), + self::todoComment( + 'NodeType::tetheredNodeTypeDefinitions() is not a 1:1 replacement of NodeType::getAutoCreatedChildNodes(). You need to change your code to work with new TetheredNodeTypeDefinition object.', ) ], $node ); - return $this->nodeFactory->createMethodCall( - $this->contentRepository_getNodeTypeManager(), - 'getTetheredNodesConfigurationForNodeType', - [$node->var] + return $this->nodeFactory->createPropertyFetch( + $node->var, + 'tetheredNodeTypeDefinitions' ); } } diff --git a/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php index 23bf140..1798783 100644 --- a/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php +++ b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php @@ -1,6 +1,7 @@ getTypeOfAutoCreatedChildNode($nodeName)" will be rewritten.', __CLASS__); } @@ -30,14 +30,15 @@ public function getRuleDefinition() : RuleDefinition /** * @return array> */ - public function getNodeTypes() : array + public function getNodeTypes(): array { return [Node\Expr\MethodCall::class]; } + /** * @param Node\Expr\MethodCall $node */ - public function refactor(Node $node) : ?Node + public function refactor(Node $node): ?Node { assert($node instanceof Node\Expr\MethodCall); @@ -59,13 +60,18 @@ public function refactor(Node $node) : ?Node $node ); - return $this->nodeFactory->createMethodCall( - $this->contentRepository_getNodeTypeManager(), - 'getTypeOfTetheredNode', - [ - $node->var, - $node->args[0] - ] - ); + return + $this->nodeFactory->createMethodCall( + $this->contentRepository_getNodeTypeManager(), + 'getNodeType', + [$this->nodeFactory->createMethodCall( + $this->nodeFactory->createPropertyFetch( + $node->var, + 'tetheredNodeTypeDefinitions' + ), + 'get', + $node->args + )] + ); } } diff --git a/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/Fixture/some_class.php.inc new file mode 100644 index 0000000..8852dea --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/Fixture/some_class.php.inc @@ -0,0 +1,33 @@ +getNodeType(); + $nodeTypeName = $nodeType->getName(); + + $nodeTypeName = $node->getNodeType()->getName(); + } +} + +?> +----- +getNodeType(); + $nodeTypeName = $nodeType->getName(); + + $nodeTypeName = $node->nodeTypeName->value; + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/NodeGetNodeTypeGetNameRectorTest.php b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/NodeGetNodeTypeGetNameRectorTest.php new file mode 100644 index 0000000..0bc35e1 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/NodeGetNodeTypeGetNameRectorTest.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/NodeGetNodeTypeGetNameRector/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/config/configured_rule.php new file mode 100644 index 0000000..c54d308 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(NodeGetNodeTypeGetNameRector::class); +}; diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class2.php.inc b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc similarity index 64% rename from tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class2.php.inc rename to tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc index 2aae8b2..358bcf6 100644 --- a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class2.php.inc +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc @@ -6,7 +6,7 @@ class SomeClass { public function run(NodeLegacyStub $node) { - $node->getNodeType()->getAutoCreatedChildNodes(); + $nodeType = $node->getNodeType(); } } @@ -18,13 +18,11 @@ use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; class SomeClass { - #[\Neos\Flow\Annotations\Inject] - protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; public function run(NodeLegacyStub $node) { // TODO 9.0 migration: Make this code aware of multiple Content Repositories. $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($node->getNodeType()); + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); } } diff --git a/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/NodeGetNodeTypeRectorTest.php b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/NodeGetNodeTypeRectorTest.php new file mode 100644 index 0000000..c8d6e0c --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/NodeGetNodeTypeRectorTest.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/NodeGetNodeTypeRector/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/config/configured_rule.php new file mode 100644 index 0000000..6174f08 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/config/configured_rule.php @@ -0,0 +1,11 @@ +rule(NodeGetNodeTypeRector::class); +}; diff --git a/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/Fixture/some_class.php.inc new file mode 100644 index 0000000..694d817 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/Fixture/some_class.php.inc @@ -0,0 +1,27 @@ +getPropertyNames(); + } +} + +?> +----- +properties)); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/NodeGetPropertyNamesRectorTest.php b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/NodeGetPropertyNamesRectorTest.php new file mode 100644 index 0000000..a489e9c --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/NodeGetPropertyNamesRectorTest.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/NodeGetPropertyNamesRector/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/config/configured_rule.php new file mode 100644 index 0000000..d1c0772 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeGetPropertyNamesRector/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(NodeGetPropertyNamesRector::class); +}; diff --git a/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector/Fixture/some_class.php.inc index f31d1dd..ec7f5b3 100644 --- a/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector/Fixture/some_class.php.inc +++ b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector/Fixture/some_class.php.inc @@ -34,7 +34,7 @@ class SomeClass // TODO 9.0 migration: Make this code aware of multiple Content Repositories. $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($parentNodeName), $nodeType); + $contentRepository->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType->name, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($parentNodeName), $nodeType->name); } } diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class.php.inc index 5ffdfc8..fe09c0d 100644 --- a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class.php.inc +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class.php.inc @@ -19,14 +19,12 @@ use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; class SomeClass { - #[\Neos\Flow\Annotations\Inject] - protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; public function run(NodeLegacyStub $node) { $nodeType = $node->getNodeType(); - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $childNodes = $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType); + // TODO 9.0 migration: NodeType::tetheredNodeTypeDefinitions() is not a 1:1 replacement of NodeType::getAutoCreatedChildNodes(). You need to change your code to work with new TetheredNodeTypeDefinition object. + + $childNodes = $nodeType->tetheredNodeTypeDefinitions; } } diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class3.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class3.php.inc deleted file mode 100644 index bd15ffb..0000000 --- a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class3.php.inc +++ /dev/null @@ -1,33 +0,0 @@ -getParent(); - $parent->getNodeType()->getAutoCreatedChildNodes(); - } -} - -?> ------ -getParent(); - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($parent->getNodeType()); - } -} - -?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class4.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class4.php.inc deleted file mode 100644 index b6a24fa..0000000 --- a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class4.php.inc +++ /dev/null @@ -1,31 +0,0 @@ -getParent()->getNodeType()->getAutoCreatedChildNodes(); - } -} - -?> ------ -contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($node->getParent()->getNodeType()); - } -} - -?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class5.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class5.php.inc deleted file mode 100644 index 11bd9f6..0000000 --- a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector/Fixture/some_class5.php.inc +++ /dev/null @@ -1,35 +0,0 @@ -getNodeType(); - foreach ($nodeType->getAutoCreatedChildNodes() as $key => $_x) { - } - } -} - -?> ------ -getNodeType(); - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - foreach ($contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType) as $key => $_x) { - } - } -} - -?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc similarity index 89% rename from tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class.php.inc rename to tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc index 4207f72..d333216 100644 --- a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class.php.inc +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc @@ -1,3 +1,4 @@ + getNodeType(); // TODO 9.0 migration: Make this code aware of multiple Content Repositories. $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $type = $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($nodeType, $nodeName); + $type = $contentRepository->getNodeTypeManager()->getNodeType($nodeType->tetheredNodeTypeDefinitions->get($nodeName)); } } diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class2.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class2.php.inc deleted file mode 100644 index d308106..0000000 --- a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class2.php.inc +++ /dev/null @@ -1,35 +0,0 @@ -getNodeType()->getTypeOfAutoCreatedChildNode($nodeName); - } -} - -?> ------ -contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($node->getNodeType(), $nodeName); - } -} - -?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class3.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class3.php.inc deleted file mode 100644 index 632bd78..0000000 --- a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/some_class3.php.inc +++ /dev/null @@ -1,37 +0,0 @@ -getParent(); - $parent->getNodeType()->getTypeOfAutoCreatedChildNode($nodeName); - } -} - -?> ------ -getParent(); - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($parent->getNodeType(), $nodeName); - } -} - -?> diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-get-child.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-get-child.php.inc new file mode 100644 index 0000000..7dc8acc --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-get-child.php.inc @@ -0,0 +1,93 @@ +getNode('path')->getName(); + + $nodeName = NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->getName(); + + foreach ($node->findChildNodes() as $childNode) { + $childNode->getName(); + } + } + + public function nodeInterface(\Neos\ContentRepository\Domain\Model\NodeInterface $node) + { + $node->getNode('path')->getName(); + + $nodeName = NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->getName(); + + foreach ($node->findChildNodes() as $childNode) { + $childNode->getName(); + } + } + + public function traversableNodeInterface(\Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface $node) + { + $node->getNode('path')->getName(); + + $nodeName = NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->getName(); + + foreach ($node->findChildNodes() as $childNode) { + $childNode->getName(); + } + } +} + +----- +getNode('path')->nodeName; + + $nodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->nodeName; + + foreach ($node->findChildNodes() as $childNode) { + $childNode->nodeName; + } + } + + public function nodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $node->getNode('path')->nodeName; + + $nodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->nodeName; + + foreach ($node->findChildNodes() as $childNode) { + $childNode->nodeName; + } + } + + public function traversableNodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $node->getNode('path')->nodeName; + + $nodeName = \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString("name"); + $node->findNamedChildNode($nodeName)->nodeName; + + foreach ($node->findChildNodes() as $childNode) { + $childNode->nodeName; + } + } +} + diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-get-parent.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-get-parent.php.inc new file mode 100644 index 0000000..05aa8ea --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-get-parent.php.inc @@ -0,0 +1,71 @@ +getParent()->getName(); + + $node->findParentNode()->getName(); + } + + public function nodeInterface(\Neos\ContentRepository\Domain\Model\NodeInterface $node) + { + $node->getParent()->getName(); + + $node->findParentNode()->getName(); + } + + public function traversableNodeInterface(\Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface $node) + { + $node->getParent()->getName(); + + $node->findParentNode()->getName(); + } +} + +----- +contentRepositoryRegistry->subgraphForNode($node); + $subgraph->findParentNode($node->aggregateId)->nodeName; + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + + $subgraph->findParentNode($node->aggregateId)->nodeName; + } + + public function nodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + $subgraph->findParentNode($node->aggregateId)->nodeName; + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + + $subgraph->findParentNode($node->aggregateId)->nodeName; + } + + public function traversableNodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + $subgraph->findParentNode($node->aggregateId)->nodeName; + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + + $subgraph->findParentNode($node->aggregateId)->nodeName; + } +} + diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-hidden-in-index.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-hidden-in-index.php.inc new file mode 100644 index 0000000..b820145 --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-hidden-in-index.php.inc @@ -0,0 +1,31 @@ +isHiddenInIndex(); + $node->setHiddenInIndex(false); + } +} +----- +getProperty('hiddenInMenu'); + // TODO 9.0 migration: !! Node::setHiddenInIndex() is not supported by the new CR. Use the "SetNodeProperties" command to change the property value for "hiddenInMenu". + + $node->setHiddenInIndex(false); + } +} diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-name.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-name.php.inc new file mode 100644 index 0000000..691a826 --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-name.php.inc @@ -0,0 +1,33 @@ +getName(); + + $node->setName('newName'); + } +} +----- +nodeName; + // TODO 9.0 migration: !! Node::setName() is not supported by the new CR. Use the "ChangeNodeAggregateName" command to change the node name. + + + $node->setName('newName'); + } +} diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc new file mode 100644 index 0000000..1729c93 --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc @@ -0,0 +1,113 @@ +getNodeTypeName(); + $node->getNodeType()->getName(); + + $nodeType = $node->getNodeType(); + $nodeType->getName(); + + /** @var NodeType $nodeType */ + $nodeType = $node->getNodeType(); + $nodeType->getName(); + } + + public function nodeInterface(\Neos\ContentRepository\Domain\Model\NodeInterface $node) + { + $node->getNodeTypeName(); + $node->getNodeType()->getName(); + + $nodeType = $node->getNodeType(); + $nodeType->getName(); + + /** @var NodeType $nodeType */ + $nodeType = $node->getNodeType(); + $nodeType->getName(); + } + + public function traversableNodeInterface(\Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface $node) + { + $node->getNodeTypeName(); + $node->getNodeType()->getName(); + + $nodeType = $node->getNodeType(); + $nodeType->getName(); + + /** @var NodeType $nodeType */ + $nodeType = $node->getNodeType(); + $nodeType->getName(); + } +} + +----- +nodeTypeName; + $node->nodeTypeName->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + /** @var NodeType $nodeType */ + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + } + + public function nodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $node->nodeTypeName; + $node->nodeTypeName->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + /** @var NodeType $nodeType */ + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + } + + public function traversableNodeInterface(\Neos\ContentRepository\Core\Projection\ContentGraph\Node $node) + { + $node->nodeTypeName; + $node->nodeTypeName->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + + /** @var NodeType $nodeType */ + $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); + $nodeType->name->value; + } +} + diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc new file mode 100644 index 0000000..60f2c81 --- /dev/null +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc @@ -0,0 +1,45 @@ +getProperty('foo'); + $bool = $node->hasProperty('foo'); + + $node->setProperty('foo', 'bar'); + + $node->removeProperty('bar'); + + $propertyNames = $node->getPropertyNames(); + } +} +----- +getProperty('foo'); + $bool = $node->hasProperty('foo'); + // TODO 9.0 migration: !! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to change property values. + + + $node->setProperty('foo', 'bar'); + // TODO 9.0 migration: !! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values. + + + $node->removeProperty('bar'); + + $propertyNames = array_keys(iterator_to_array($node->properties)); + } +} From d9aba0fcfd879296715df9d918368d5b65c40f3c Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Mon, 18 Nov 2024 17:34:36 +0100 Subject: [PATCH 2/4] FEATURE: Improve Node and Node interfaces rewrites --- docs/rules_overview.md | 106 +++++++++++++++++++++++++++++++++++------ 1 file changed, 92 insertions(+), 14 deletions(-) diff --git a/docs/rules_overview.md b/docs/rules_overview.md index e342d2f..c869dc1 100644 --- a/docs/rules_overview.md +++ b/docs/rules_overview.md @@ -1,4 +1,4 @@ -# 58 Rules Overview +# 61 Rules Overview ## ContentDimensionCombinatorGetAllAllowedCombinationsRector @@ -1319,7 +1319,7 @@ return static function (RectorConfig $rectorConfig): void { { - $parentNode = $node->findParentNode(); + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); -+ $parentNode = $subgraph->findParentNode($node->nodeAggregateId); ++ $parentNode = $subgraph->findParentNode($node->aggregateId); } } @@ -1347,7 +1347,7 @@ return static function (RectorConfig $rectorConfig): void { + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + // TODO 9.0 migration: Try to remove the iterator_to_array($nodes) call. + -+ foreach (iterator_to_array($subgraph->findChildNodes($node->nodeAggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter::create(pagination: ['limit' => 10, 'offset' => 100]))) as $node) { ++ foreach (iterator_to_array($subgraph->findChildNodes($node->aggregateId, \Neos\ContentRepository\Core\Projection\ContentGraph\Filter\FindChildNodesFilter::create(pagination: ['limit' => 10, 'offset' => 100]))) as $node) { } } } @@ -1426,7 +1426,7 @@ return static function (RectorConfig $rectorConfig): void { { - return $node->getDepth(); + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); -+ return $subgraph->findNodePath($node->nodeAggregateId)->getDepth(); ++ return $subgraph->findNodePath($node->aggregateId)->getDepth(); } } @@ -1480,7 +1480,62 @@ return static function (RectorConfig $rectorConfig): void { - $nodeIdentifier = $node->getIdentifier(); + // TODO 9.0 migration: Check if you could change your code to work with the NodeAggregateId value object instead. + -+ $nodeIdentifier = $node->nodeAggregateId->value; ++ $nodeIdentifier = $node->aggregateId->value; + } + } + + ?> +``` + +
+ +## NodeGetNodeTypeGetNameRector + +`"NodeInterface::getNodeType()->getName()"` will be rewritten + +- class: [`Neos\Rector\ContentRepository90\Rules\NodeGetNodeTypeGetNameRector`](../src/ContentRepository90/Rules/NodeGetNodeTypeGetNameRector.php) + +```diff + getNodeType(); + $nodeTypeName = $nodeType->getName(); + +- $nodeTypeName = $node->getNodeType()->getName(); ++ $nodeTypeName = $node->nodeTypeName->value; + } + } + + ?> +``` + +
+ +## NodeGetNodeTypeRector + +`"NodeInterface::getNodeType()"` will be rewritten + +- class: [`Neos\Rector\ContentRepository90\Rules\NodeGetNodeTypeRector`](../src/ContentRepository90/Rules/NodeGetNodeTypeRector.php) + +```diff + getNodeType(); ++ // TODO 9.0 migration: Make this code aware of multiple Content Repositories. ++ $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); ++ $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); } } @@ -1506,7 +1561,7 @@ return static function (RectorConfig $rectorConfig): void { { - return $node->getParent(); + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); -+ return $subgraph->findParentNode($node->nodeAggregateId); ++ return $subgraph->findParentNode($node->aggregateId); } } @@ -1534,7 +1589,32 @@ return static function (RectorConfig $rectorConfig): void { + $subgraph = $this->contentRepositoryRegistry->subgraphForNode($node); + // TODO 9.0 migration: Try to remove the (string) cast and make your code more type-safe. + -+ return (string) $subgraph->findNodePath($node->nodeAggregateId); ++ return (string) $subgraph->findNodePath($node->aggregateId); + } + } + + ?> +``` + +
+ +## NodeGetPropertyNamesRector + +"$nodeType->allowsGrandchildNodeType($parentNodeName, `$nodeType)"` will be rewritten. + +- class: [`Neos\Rector\ContentRepository90\Rules\NodeGetPropertyNamesRector`](../src/ContentRepository90/Rules/NodeGetPropertyNamesRector.php) + +```diff + getPropertyNames(); ++ $propertyNames = array_keys(iterator_to_array($node->properties)); } } @@ -1645,7 +1725,7 @@ return static function (RectorConfig $rectorConfig): void { + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); - $grandParentsNodeType->allowsGrandchildNodeType($parentNodeName, $nodeType); -+ $contentRepository->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($parentNodeName), $nodeType); ++ $contentRepository->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType->name, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($parentNodeName), $nodeType->name); } } @@ -1667,15 +1747,13 @@ return static function (RectorConfig $rectorConfig): void { class SomeClass { -+ #[\Neos\Flow\Annotations\Inject] -+ protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; public function run(NodeLegacyStub $node) { $nodeType = $node->getNodeType(); - $childNodes = $nodeType->getAutoCreatedChildNodes(); -+ // TODO 9.0 migration: Make this code aware of multiple Content Repositories. -+ $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); -+ $childNodes = $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType); ++ // TODO 9.0 migration: NodeType::tetheredNodeTypeDefinitions() is not a 1:1 replacement of NodeType::getAutoCreatedChildNodes(). You need to change your code to work with new TetheredNodeTypeDefinition object. ++ ++ $childNodes = $nodeType->tetheredNodeTypeDefinitions; } } @@ -1732,7 +1810,7 @@ return static function (RectorConfig $rectorConfig): void { - $type = $nodeType->getTypeOfAutoCreatedChildNode($nodeName); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); -+ $type = $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($nodeType, $nodeName); ++ $type = $contentRepository->getNodeTypeManager()->getNodeType($nodeType->tetheredNodeTypeDefinitions->get($nodeName)); } } From 422b1a755174389d5662ad387c0279600f66d301 Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Tue, 19 Nov 2024 10:45:51 +0100 Subject: [PATCH 3/4] FEATURE: Improve Node and Node interfaces rewrites --- .../Rules/NodeGetNodeTypeRector.php | 10 ++++++---- ...TypeGetTypeOfAutoCreatedChildNodeRector.php | 5 ++--- .../Fixture/some_class.php.inc | 3 +-- .../Fixture/default.php.inc | 2 +- .../node-nodetype-and-nodetypename.php.inc | 18 ++++++------------ 5 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php b/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php index eac3a96..b99afa8 100644 --- a/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php +++ b/src/ContentRepository90/Rules/NodeGetNodeTypeRector.php @@ -50,10 +50,12 @@ public function refactor(Node $node): ?Node $this->nodesToAddCollector->addNodesBeforeNode( [ - self::withTodoComment( - 'Make this code aware of multiple Content Repositories.', - self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))), - ) + self::assign( + 'contentRepository', + $this->this_contentRepositoryRegistry_get( + $this->nodeFactory->createPropertyFetch($node->var, 'contentRepositoryId') + ) + ), ], $node ); diff --git a/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php index 1798783..ce29ba4 100644 --- a/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php +++ b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php @@ -4,14 +4,13 @@ namespace Neos\Rector\ContentRepository90\Rules; +use Neos\ContentRepository\Core\NodeType\NodeType; use Neos\Rector\Utility\CodeSampleLoader; use PhpParser\Node; use PHPStan\Type\ObjectType; use Rector\Core\Rector\AbstractRector; use Rector\PostRector\Collector\NodesToAddCollector; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; -use Neos\ContentRepository\Core\NodeType\NodeType; -use PhpParser\NodeDumper; final class NodeTypeGetTypeOfAutoCreatedChildNodeRector extends AbstractRector { @@ -53,7 +52,7 @@ public function refactor(Node $node): ?Node $this->nodesToAddCollector->addNodesBeforeNode( [ self::withTodoComment( - 'Make this code aware of multiple Content Repositories.', + 'Make this code aware of multiple Content Repositories. If you have a Node object around you can use $node->contentRepositoryId.', self::assign('contentRepository', $this->this_contentRepositoryRegistry_get($this->contentRepositoryId_fromString('default'))), ) ], diff --git a/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc index 358bcf6..7658245 100644 --- a/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc +++ b/tests/ContentRepository90/Rules/NodeGetNodeTypeRector/Fixture/some_class.php.inc @@ -20,8 +20,7 @@ class SomeClass { public function run(NodeLegacyStub $node) { - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); } } diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc index d333216..297413a 100644 --- a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector/Fixture/default.php.inc @@ -29,7 +29,7 @@ class SomeClass { $nodeName = NodeName::fromString('name'); $nodeType = $node->getNodeType(); - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. If you have a Node object around you can use $node->contentRepositoryId. $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); $type = $contentRepository->getNodeTypeManager()->getNodeType($nodeType->tetheredNodeTypeDefinitions->get($nodeName)); } diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc index 1729c93..5abcba6 100644 --- a/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-nodetype-and-nodetypename.php.inc @@ -63,13 +63,11 @@ class SomeClass extends AnotherClass { $node->nodeTypeName; $node->nodeTypeName->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); $nodeType->name->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); /** @var NodeType $nodeType */ $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); @@ -80,13 +78,11 @@ class SomeClass extends AnotherClass { $node->nodeTypeName; $node->nodeTypeName->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); $nodeType->name->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); /** @var NodeType $nodeType */ $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); @@ -97,13 +93,11 @@ class SomeClass extends AnotherClass { $node->nodeTypeName; $node->nodeTypeName->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); $nodeType->name->value; - // TODO 9.0 migration: Make this code aware of multiple Content Repositories. - $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\SharedModel\ContentRepository\ContentRepositoryId::fromString('default')); + $contentRepository = $this->contentRepositoryRegistry->get($node->contentRepositoryId); /** @var NodeType $nodeType */ $nodeType = $contentRepository->getNodeTypeManager()->getNodeType($node->nodeTypeName); From 79aab6ea92a244151be49ac28d5ded443d84ed3a Mon Sep 17 00:00:00 2001 From: Denny Lubitz Date: Wed, 20 Nov 2024 10:45:53 +0100 Subject: [PATCH 4/4] FEATURE: Improve Node and Node interfaces rewrites --- config/set/contentrepository-90.php | 2 +- .../ContentRepository90/Fixture/Node/node-properties.php.inc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 4c556d7..b3b6314 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -153,7 +153,7 @@ // hasProperty -> compatible with ES CR Node (nothing to do) // getProperty -> compatible with ES CR Node (nothing to do) // removeProperty - $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'removeProperty', '!! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values.'); + $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'removeProperty', '!! Node::removeProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values.'); // getProperties -> PropertyCollectionInterface $methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getProperties', 'properties'); // getPropertyNames diff --git a/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc b/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc index 60f2c81..d26e56f 100644 --- a/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc +++ b/tests/Sets/ContentRepository90/Fixture/Node/node-properties.php.inc @@ -35,7 +35,7 @@ class SomeClass extends AnotherClass $node->setProperty('foo', 'bar'); - // TODO 9.0 migration: !! Node::setProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values. + // TODO 9.0 migration: !! Node::removeProperty() is not supported by the new CR. Use the "SetNodeProperties" command to remove a property values. $node->removeProperty('bar');