From eccef627bf56778dacda51ec31887b512ad5aba8 Mon Sep 17 00:00:00 2001 From: Denny Lubitz <lubitz@vivomedia.de> Date: Fri, 3 Nov 2023 13:58:02 +0100 Subject: [PATCH] TASK Refactor nodetype --- config/set/contentrepository-90.php | 52 ++++++++---- .../Legacy/NodeLegacyStub.php | 10 +++ ...NodeTypeAllowsGrandchildNodeTypeRector.php | 79 +++++++++++++++++++ ...NodeTypeGetAutoCreatedChildNodesRector.php | 67 ++++++++++++++++ ...ypeGetTypeOfAutoCreatedChildNodeRector.php | 71 +++++++++++++++++ .../Fixture/some_class.php.inc | 41 ++++++++++ .../NodeTypeAllowsGrandchildNodeTypeTest.php | 31 ++++++++ .../config/configured_rule.php | 17 ++++ .../Fixture/some_class.php.inc | 33 ++++++++ .../Fixture/some_class2.php.inc | 31 ++++++++ .../Fixture/some_class3.php.inc | 33 ++++++++ .../Fixture/some_class4.php.inc | 31 ++++++++ .../Fixture/some_class5.php.inc | 35 ++++++++ .../NodeTypeGetAutoCreatedChildNodesTest.php | 31 ++++++++ .../config/configured_rule.php | 17 ++++ .../Fixture/some_class.php.inc | 37 +++++++++ .../Fixture/some_class2.php.inc | 35 ++++++++ .../Fixture/some_class3.php.inc | 37 +++++++++ ...eTypeGetTypeOfAutoCreatedChildNodeTest.php | 31 ++++++++ .../config/configured_rule.php | 17 ++++ 20 files changed, 720 insertions(+), 16 deletions(-) create mode 100644 src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php create mode 100644 src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php create mode 100644 src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/Fixture/some_class.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/NodeTypeAllowsGrandchildNodeTypeTest.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/config/configured_rule.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class2.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class3.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class4.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class5.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/NodeTypeGetAutoCreatedChildNodesTest.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/config/configured_rule.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class2.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class3.php.inc create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/NodeTypeGetTypeOfAutoCreatedChildNodeTest.php create mode 100644 tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/config/configured_rule.php diff --git a/config/set/contentrepository-90.php b/config/set/contentrepository-90.php index 9383089..dc78bca 100644 --- a/config/set/contentrepository-90.php +++ b/config/set/contentrepository-90.php @@ -56,6 +56,13 @@ use Neos\Rector\ContentRepository90\Rules\ContextIsInBackendRector; use Neos\ContentRepository\Core\Projection\ContentGraph\Node; use Neos\Rector\ContentRepository90\Rules\FusionPrimaryContentRector; +use Neos\Rector\ContentRepository90\Rules\NodeTypeGetAutoCreatedChildNodesRector; +use Neos\Rector\ContentRepository90\Rules\NodeTypeHasAutoCreatedChildNodesRector; +use Rector\Renaming\Rector\MethodCall\RenameMethodRector; +use Rector\Renaming\ValueObject\MethodCallRename; +use Neos\ContentRepository\Core\NodeType\NodeType; +use Neos\Rector\ContentRepository90\Rules\NodeTypeGetTypeOfAutoCreatedChildNodeRector; +use Neos\Rector\ContentRepository90\Rules\NodeTypeAllowsGrandchildNodeTypeRector; return static function (RectorConfig $rectorConfig): void { // Register FusionFileProcessor. All Fusion Rectors will be auto-registered at this processor. @@ -119,7 +126,7 @@ // setHidden // isHidden $rectorConfig->rule(NodeIsHiddenRector::class); - // TODO: Fusion NodeAccess + // TODO: Fusion NodeAccess // setHiddenBeforeDateTime $methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setHiddenBeforeDateTime', '!! Node::setHiddenBeforeDateTime() 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.'); // getHiddenBeforeDateTime @@ -144,9 +151,9 @@ // Fusion: .depth -> Neos.NodeAccess.depth(node) $rectorConfig->rule(FusionNodePathRector::class); // getContextPath - // TODO: PHP - // TODO: Fusion - // - NodeAddress + LOG (WARNING) + // TODO: PHP + // TODO: Fusion + // - NodeAddress + LOG (WARNING) // getDepth $rectorConfig->rule(NodeGetDepthRector::class); // Fusion: .depth -> Neos.Node.depth(node) @@ -195,13 +202,13 @@ // getContext() // getContext()->getWorkspace() $rectorConfig->rule(NodeGetContextGetWorkspaceRector::class); - // TODO: Fusion + // TODO: Fusion // getContext()->getWorkspaceName() $rectorConfig->rule(NodeGetContextGetWorkspaceNameRector::class); - // TODO: Fusion + // TODO: Fusion // getDimensions() $rectorConfig->rule(NodeGetDimensionsRector::class); - // TODO: Fusion + // TODO: Fusion // createVariantForContext() // isAutoCreated() // getOtherNodeVariants() @@ -230,8 +237,21 @@ * Neos\ContentRepository\Core\NodeType\NodeType */ // getName() - $rectorConfig->rule(rectorClass: FusionNodeTypeNameRector::class); - $rectorConfig->rule(rectorClass: NodeTypeGetNameRector::class); + $rectorConfig->rule(FusionNodeTypeNameRector::class); + $rectorConfig->rule(NodeTypeGetNameRector::class); + // getAutoCreatedChildNodes + $rectorConfig->rule(NodeTypeGetAutoCreatedChildNodesRector::class); + // hasAutoCreatedChildNode + $rectorConfig->ruleWithConfiguration(RenameMethodRector::class, [new MethodCallRename( + NodeType::class, + 'hasAutoCreatedChildNode', + 'hasTetheredNode' + )]); + // getTypeOfAutoCreatedChildNode + $rectorConfig->rule(NodeTypeGetTypeOfAutoCreatedChildNodeRector::class); + // allowsGrandchildNodeType + $rectorConfig->rule(NodeTypeAllowsGrandchildNodeTypeRector::class); + /** * Neos\ContentRepository\Domain\Projection\Content\TraversableNodeInterface @@ -240,17 +260,17 @@ // findParentNode() -> TraversableNodeInterface $rectorConfig->rule(NodeFindParentNodeRector::class); // findNodePath() -> NodePath - // TODO: PHP + // TODO: PHP // findNamedChildNode(NodeName $nodeName): TraversableNodeInterface; - // TODO: PHP + // TODO: PHP // findChildNodes(NodeTypeConstraints $nodeTypeConstraints = null, int $limit = null, int $offset = null): TraversableNodes; - // TODO: PHP + // TODO: PHP // countChildNodes(NodeTypeConstraints $nodeTypeConstraints = null): int; - // TODO: PHP + // TODO: PHP // findReferencedNodes(): TraversableNodes; - // TODO: PHP + // TODO: PHP // findNamedReferencedNodes(PropertyName $edgeName): TraversableNodes; - // TODO: PHP + // TODO: PHP // findReferencingNodes() -> threw exception in <= Neos 8.0 - so nobody could have used this // findNamedReferencingNodes() -> threw exception in <= Neos 8.0 - so nobody could have used this @@ -327,7 +347,7 @@ /** * Neos.Neos:PrimaryContent */ - $rectorConfig->rule(FusionPrimaryContentRector::class ); + $rectorConfig->rule(FusionPrimaryContentRector::class); /** * SPECIAL rules diff --git a/src/ContentRepository90/Legacy/NodeLegacyStub.php b/src/ContentRepository90/Legacy/NodeLegacyStub.php index 87125ef..fe75b7b 100644 --- a/src/ContentRepository90/Legacy/NodeLegacyStub.php +++ b/src/ContentRepository90/Legacy/NodeLegacyStub.php @@ -2,6 +2,8 @@ namespace Neos\Rector\ContentRepository90\Legacy; +use Neos\ContentRepository\Core\NodeType\NodeType; + /** * @deprecated */ @@ -11,4 +13,12 @@ class NodeLegacyStub public function getContext() : LegacyContextStub { return new LegacyContextStub([]); } + + public function getNodeType(): NodeType { + return new NodeType('foo', [], [], null); + } + + public function getParent(): NodeLegacyStub { + return new NodeLegacyStub(); + } } diff --git a/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php b/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php new file mode 100644 index 0000000..298973e --- /dev/null +++ b/src/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeTypeRector.php @@ -0,0 +1,79 @@ +<?php + +declare (strict_types=1); + +namespace Neos\Rector\ContentRepository90\Rules; + +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 +{ + use AllTraits; + + public function __construct( + private readonly NodesToAddCollector $nodesToAddCollector + ) { + } + + public function getRuleDefinition(): RuleDefinition + { + return CodeSampleLoader::fromFile('"$nodeType->allowsGrandchildNodeType($parentNodeName, $nodeType)" will be rewritten.', __CLASS__); + } + + /** + * @return array<class-string<Node>> + */ + 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(NodeType::class))) { + return null; + } + + if (!$this->isName($node->name, 'allowsGrandchildNodeType')) { + 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(), + 'isNodeTypeAllowedAsChildToTetheredNode', + [ + $node->var, + $this->nodeFactory->createStaticCall( + \Neos\ContentRepository\Core\SharedModel\Node\NodeName::class, + 'fromString', + [ + $node->args[0] + ] + ), + $node->args[1] + ] + ); + } +} diff --git a/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php b/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php new file mode 100644 index 0000000..36eb25b --- /dev/null +++ b/src/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodesRector.php @@ -0,0 +1,67 @@ +<?php + +declare (strict_types=1); +namespace Neos\Rector\ContentRepository90\Rules; + +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; + +final class NodeTypeGetAutoCreatedChildNodesRector extends AbstractRector +{ + use AllTraits; + + public function __construct( + private readonly NodesToAddCollector $nodesToAddCollector + ) + { + } + + public function getRuleDefinition() : RuleDefinition + { + return CodeSampleLoader::fromFile('"$nodeType->getAutoCreatedChildNodes()" will be rewritten.', __CLASS__); + } + + /** + * @return array<class-string<Node>> + */ + 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(NodeType::class))) { + return null; + } + + if (!$this->isName($node->name, 'getAutoCreatedChildNodes')) { + 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(), + 'getTetheredNodesConfigurationForNodeType', + [$node->var] + ); + } +} diff --git a/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php new file mode 100644 index 0000000..23bf140 --- /dev/null +++ b/src/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNodeRector.php @@ -0,0 +1,71 @@ +<?php + +declare (strict_types=1); +namespace Neos\Rector\ContentRepository90\Rules; + +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 +{ + use AllTraits; + + public function __construct( + private readonly NodesToAddCollector $nodesToAddCollector + ) + { + } + + public function getRuleDefinition() : RuleDefinition + { + return CodeSampleLoader::fromFile('"$nodeType->getTypeOfAutoCreatedChildNode($nodeName)" will be rewritten.', __CLASS__); + } + + /** + * @return array<class-string<Node>> + */ + 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(NodeType::class))) { + return null; + } + + if (!$this->isName($node->name, 'getTypeOfAutoCreatedChildNode')) { + 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(), + 'getTypeOfTetheredNode', + [ + $node->var, + $node->args[0] + ] + ); + } +} diff --git a/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/Fixture/some_class.php.inc new file mode 100644 index 0000000..2f59737 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/Fixture/some_class.php.inc @@ -0,0 +1,41 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $parentNodeName = 'name'; + $nodeType = $node->getNodeType(); + $grandParentsNodeType = $node->getParent()->getParent()->getNodeType(); + + $grandParentsNodeType->allowsGrandchildNodeType($parentNodeName, $nodeType); + } +} + +?> +----- +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; + public function run(NodeLegacyStub $node) + { + $parentNodeName = 'name'; + $nodeType = $node->getNodeType(); + $grandParentsNodeType = $node->getParent()->getParent()->getNodeType(); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\Factory\ContentRepositoryId::fromString('default')); + + $contentRepository->getNodeTypeManager()->isNodeTypeAllowedAsChildToTetheredNode($grandParentsNodeType, \Neos\ContentRepository\Core\SharedModel\Node\NodeName::fromString($parentNodeName), $nodeType); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/NodeTypeAllowsGrandchildNodeTypeTest.php b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/NodeTypeAllowsGrandchildNodeTypeTest.php new file mode 100644 index 0000000..caf58c8 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/NodeTypeAllowsGrandchildNodeTypeTest.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +namespace Neos\Rector\Tests\ContentRepository90\Rules\NodeGetParentRector; + +use Rector\Testing\PHPUnit\AbstractRectorTestCase; + +final class NodeTypeAllowsGrandchildNodeTypeTest extends AbstractRectorTestCase +{ + /** + * @dataProvider provideData() + */ + public function test(string $fileInfo): void + { + $this->doTestFile($fileInfo); + } + + /** + * @return \Iterator<string> + */ + 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/NodeTypeAllowsGrandchildNodeType/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/config/configured_rule.php new file mode 100644 index 0000000..01d2de1 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeAllowsGrandchildNodeType/config/configured_rule.php @@ -0,0 +1,17 @@ +<?php + +declare (strict_types=1); + +use Rector\Config\RectorConfig; +use Neos\Rector\Generic\Rules\InjectServiceIfNeededRector; +use Neos\Rector\Generic\ValueObject\AddInjection; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +use Neos\Rector\ContentRepository90\Rules\NodeTypeAllowsGrandchildNodeTypeRector; + +return static function (RectorConfig $rectorConfig) : void { + $rectorConfig->rule(NodeTypeAllowsGrandchildNodeTypeRector::class); + + $rectorConfig->ruleWithConfiguration(InjectServiceIfNeededRector::class, [ + new AddInjection('contentRepositoryRegistry', ContentRepositoryRegistry::class), + ]); +}; diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class.php.inc new file mode 100644 index 0000000..e20fb47 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class.php.inc @@ -0,0 +1,33 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $nodeType = $node->getNodeType(); + $childNodes = $nodeType->getAutoCreatedChildNodes(); + } +} + +?> +----- +<?php + +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\Factory\ContentRepositoryId::fromString('default')); + $childNodes = $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class2.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class2.php.inc new file mode 100644 index 0000000..c6f4cef --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class2.php.inc @@ -0,0 +1,31 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $node->getNodeType()->getAutoCreatedChildNodes(); + } +} + +?> +----- +<?php + +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\Factory\ContentRepositoryId::fromString('default')); + $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($node->getNodeType()); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class3.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class3.php.inc new file mode 100644 index 0000000..4531128 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class3.php.inc @@ -0,0 +1,33 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $parent = $node->getParent(); + $parent->getNodeType()->getAutoCreatedChildNodes(); + } +} + +?> +----- +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; + public function run(NodeLegacyStub $node) + { + $parent = $node->getParent(); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\Factory\ContentRepositoryId::fromString('default')); + $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($parent->getNodeType()); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class4.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class4.php.inc new file mode 100644 index 0000000..220043a --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class4.php.inc @@ -0,0 +1,31 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $node->getParent()->getNodeType()->getAutoCreatedChildNodes(); + } +} + +?> +----- +<?php + +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\Factory\ContentRepositoryId::fromString('default')); + $contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($node->getParent()->getNodeType()); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class5.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class5.php.inc new file mode 100644 index 0000000..72f4a96 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/Fixture/some_class5.php.inc @@ -0,0 +1,35 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $nodeType = $node->getNodeType(); + foreach ($nodeType->getAutoCreatedChildNodes() as $key => $_x) { + } + } +} + +?> +----- +<?php + +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\Factory\ContentRepositoryId::fromString('default')); + foreach ($contentRepository->getNodeTypeManager()->getTetheredNodesConfigurationForNodeType($nodeType) as $key => $_x) { + } + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/NodeTypeGetAutoCreatedChildNodesTest.php b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/NodeTypeGetAutoCreatedChildNodesTest.php new file mode 100644 index 0000000..11b6617 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/NodeTypeGetAutoCreatedChildNodesTest.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +namespace Neos\Rector\Tests\ContentRepository90\Rules\NodeGetParentRector; + +use Rector\Testing\PHPUnit\AbstractRectorTestCase; + +final class NodeTypeGetAutoCreatedChildNodesTest extends AbstractRectorTestCase +{ + /** + * @dataProvider provideData() + */ + public function test(string $fileInfo): void + { + $this->doTestFile($fileInfo); + } + + /** + * @return \Iterator<string> + */ + 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/NodeTypeGetAutoCreatedChildNodes/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/config/configured_rule.php new file mode 100644 index 0000000..5c678bb --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetAutoCreatedChildNodes/config/configured_rule.php @@ -0,0 +1,17 @@ +<?php + +declare (strict_types=1); + +use Rector\Config\RectorConfig; +use Neos\Rector\ContentRepository90\Rules\NodeTypeGetAutoCreatedChildNodesRector; +use Neos\Rector\Generic\Rules\InjectServiceIfNeededRector; +use Neos\Rector\Generic\ValueObject\AddInjection; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; + +return static function (RectorConfig $rectorConfig) : void { + $rectorConfig->rule(NodeTypeGetAutoCreatedChildNodesRector::class); + + $rectorConfig->ruleWithConfiguration(InjectServiceIfNeededRector::class, [ + new AddInjection('contentRepositoryRegistry', ContentRepositoryRegistry::class), + ]); +}; diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class.php.inc new file mode 100644 index 0000000..7bc24dc --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class.php.inc @@ -0,0 +1,37 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + $nodeType = $node->getNodeType(); + $type = $nodeType->getTypeOfAutoCreatedChildNode($nodeName); + } +} + +?> +----- +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + $nodeType = $node->getNodeType(); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\Factory\ContentRepositoryId::fromString('default')); + $type = $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($nodeType, $nodeName); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class2.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class2.php.inc new file mode 100644 index 0000000..1edb09a --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class2.php.inc @@ -0,0 +1,35 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + $node->getNodeType()->getTypeOfAutoCreatedChildNode($nodeName); + } +} + +?> +----- +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\Factory\ContentRepositoryId::fromString('default')); + $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($node->getNodeType(), $nodeName); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class3.php.inc b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class3.php.inc new file mode 100644 index 0000000..a2c4eeb --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/Fixture/some_class3.php.inc @@ -0,0 +1,37 @@ +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + $parent = $node->getParent(); + $parent->getNodeType()->getTypeOfAutoCreatedChildNode($nodeName); + } +} + +?> +----- +<?php + +use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub; +use Neos\ContentRepository\Core\SharedModel\Node\NodeName; + +class SomeClass +{ + #[\Neos\Flow\Annotations\Inject] + protected \Neos\ContentRepositoryRegistry\ContentRepositoryRegistry $contentRepositoryRegistry; + public function run(NodeLegacyStub $node) + { + $nodeName = NodeName::fromString('name'); + $parent = $node->getParent(); + // TODO 9.0 migration: Make this code aware of multiple Content Repositories. + $contentRepository = $this->contentRepositoryRegistry->get(\Neos\ContentRepository\Core\Factory\ContentRepositoryId::fromString('default')); + $contentRepository->getNodeTypeManager()->getTypeOfTetheredNode($parent->getNodeType(), $nodeName); + } +} + +?> diff --git a/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/NodeTypeGetTypeOfAutoCreatedChildNodeTest.php b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/NodeTypeGetTypeOfAutoCreatedChildNodeTest.php new file mode 100644 index 0000000..e2e32ec --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/NodeTypeGetTypeOfAutoCreatedChildNodeTest.php @@ -0,0 +1,31 @@ +<?php + +declare(strict_types=1); + +namespace Neos\Rector\Tests\ContentRepository90\Rules\NodeGetParentRector; + +use Rector\Testing\PHPUnit\AbstractRectorTestCase; + +final class NodeTypeGetTypeOfAutoCreatedChildNodeTest extends AbstractRectorTestCase +{ + /** + * @dataProvider provideData() + */ + public function test(string $fileInfo): void + { + $this->doTestFile($fileInfo); + } + + /** + * @return \Iterator<string> + */ + 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/NodeTypeGetTypeOfAutoCreatedChildNode/config/configured_rule.php b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/config/configured_rule.php new file mode 100644 index 0000000..c6e4889 --- /dev/null +++ b/tests/ContentRepository90/Rules/NodeTypeGetTypeOfAutoCreatedChildNode/config/configured_rule.php @@ -0,0 +1,17 @@ +<?php + +declare (strict_types=1); + +use Rector\Config\RectorConfig; +use Neos\Rector\Generic\Rules\InjectServiceIfNeededRector; +use Neos\Rector\Generic\ValueObject\AddInjection; +use Neos\ContentRepositoryRegistry\ContentRepositoryRegistry; +use Neos\Rector\ContentRepository90\Rules\NodeTypeGetTypeOfAutoCreatedChildNodeRector; + +return static function (RectorConfig $rectorConfig) : void { + $rectorConfig->rule(NodeTypeGetTypeOfAutoCreatedChildNodeRector::class); + + $rectorConfig->ruleWithConfiguration(InjectServiceIfNeededRector::class, [ + new AddInjection('contentRepositoryRegistry', ContentRepositoryRegistry::class), + ]); +};