neos / rector

Neos Rector Recipes for code migrations
6 stars 4 forks source link

Migrate `Node::getNodeType` #57

Open mhsdesign opened 4 months ago

mhsdesign commented 4 months ago

Following code should be migrated:

For fusion:

- ${node.nodeType.name}
+ ${q(node).nodeTypeName()} 
- ${node.nodeType}
+ ${Neos.Node.getNodeType(node)}
- $node->getNodeTypeName();
+ $node->nodeTypeName;
- $node->getNodeType()->getName();
+ $node->nodeTypeName->value;
- $nodeType->getName();
+ $nodeType->name->value;

(existing migration)

- $node->getNodeType();
+ $nodeTypeManger = ...;
+ $nodeTypeManager->getNodeType($node->nodeTypeName);

These rector migration would need to be adjusted so they dont pass the $nodeType to the methods, but $nodeType->name:

- $node->getNodeType()->getTypeOfAutoCreatedChildNode(NodeName::fromString('name'));
+ $nodeTypeManager->getTypeOfTetheredNode($node->nodeTypeName, NodeName::fromString('name'));
- foreach ($nodeType->getAutoCreatedChildNodes() as $rawNodeName => $childNodeType) {
-     $nodeName = NodeName::fromString($rawNodeName);
+ foreach ($nodeType->tetheredNodeTypeDefinitions as $tetheredNodeTypeDefinition) {
+     $nodeName = $tetheredNodeTypeDefinition->name;
+     $childNodeType = $nodeTypeManager->getNodeType($tetheredNodeTypeDefinition->nodeTypeName);

- $nodeType->hasAutoCreatedChildNode($nodeName);
+ $nodeType->tetheredNodeTypeDefinitions->contain($nodeName);

- $parentsNodeType->getTypeOfAutoCreatedChildNode($nodeName)->name;
+ $parentsNodeType->tetheredNodeTypeDefinitions->get($nodeName)->nodeTypeName;

- $parentsNodeType->getTypeOfAutoCreatedChildNode($nodeName);
+ $nodeTypeManager->getNodeType($parentsNodeType->tetheredNodeTypeDefinitions->get($nodeName));

- $grandParentsNodeType->allowsGrandchildNodeType($parentNodeName->value, $nodeType);
+ $nodeTypeManager->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType->name, $parentNodeName, $nodeType->name);
mhsdesign commented 4 months ago

@dlubitz i have the feeling that the migrations cant be possible as clean as suggested and will likely look like having an obsolete step in between (fetching the nodeType first)

- $node->getNodeType()->getName();
+ $nodeTypeManager->getNodeType($node->nodeTypeName)->name->value;
- $node->getNodeType()->getTypeOfAutoCreatedChildNode(NodeName::fromString('name'));
+ $nodeTypeManager->getTypeOfTetheredNode($nodeTypeManager->getNodeType($node->nodeTypeName)->name, NodeName::fromString('name'));

... or we can have a rector rule to normalize $nodeTypeManager->getNodeType($node->nodeTypeName)->name to $node->nodeTypeName 😂

dlubitz commented 4 months ago

https://github.com/neos/neos-development-collection/pull/4906#issuecomment-2035430771

Todo these rector migration would need to be adjusted so they dont pass the $nodeType to the methods, but $nodeType->name:

  • NodeTypeGetAutoCreatedChildNodesRector
  • NodeTypeGetTypeOfAutoCreatedChildNodeRector
  • NodeTypeAllowsGrandchildNodeTypeRector