Skip to content

Commit

Permalink
TASK Refector context methods
Browse files Browse the repository at this point in the history
  • Loading branch information
dlubitz committed Nov 1, 2023
1 parent d9c55cd commit 70bd4c5
Show file tree
Hide file tree
Showing 34 changed files with 116 additions and 112 deletions.
44 changes: 22 additions & 22 deletions config/set/contentrepository-90.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,47 +95,47 @@
*/
// setName
// getName
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getName', 'nodeName');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getName', 'nodeName');
// getLabel -> compatible with ES CR node (nothing to do)
// setProperty
// hasProperty -> compatible with ES CR Node (nothing to do)
// getProperty -> compatible with ES CR Node (nothing to do)
// removeProperty
// getProperties -> PropertyCollectionInterface
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getProperties', 'properties');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getProperties', 'properties');
// getPropertyNames
// setContentObject -> DEPRECATED / NON-FUNCTIONAL
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::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).');
$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
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getContentObject', '!! Node::getContentObject() is not supported by the new CR. Referencing objects can be done by storing them in Node::properties (and the serialization/deserialization is extensible).');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getContentObject', '!! Node::getContentObject() is not supported by the new CR. Referencing objects can be done by storing them in Node::properties (and the serialization/deserialization is extensible).');
// unsetContentObject -> DEPRECATED / NON-FUNCTIONAL
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::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).');
$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
// getNodeType: NodeType
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getNodeType', 'nodeType');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getNodeType', 'nodeType');
// setHidden
// isHidden
$rectorConfig->rule(NodeIsHiddenRector::class);
// TODO: Fusion NodeAccess
// setHiddenBeforeDateTime
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::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.');
$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
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getHiddenBeforeDateTime', '!! Node::getHiddenBeforeDateTime() 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.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getHiddenBeforeDateTime', '!! Node::getHiddenBeforeDateTime() 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.');
$fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('hiddenBeforeDateTime', 'Line %LINE: !! node.hiddenBeforeDateTime 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.');
// setHiddenAfterDateTime
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'setHiddenAfterDateTime', '!! Node::setHiddenAfterDateTime() 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.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setHiddenAfterDateTime', '!! Node::setHiddenAfterDateTime() 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.');
// getHiddenAfterDateTime
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::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.');
$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.');
$fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('hiddenAfterDateTime', 'Line %LINE: !! node.hiddenAfterDateTime 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.');
// setHiddenInIndex
// isHiddenInIndex
$rectorConfig->rule(NodeIsHiddenInIndexRector::class);
// Fusion: .hiddenInIndex -> node.properties._hiddenInIndex
$rectorConfig->rule(FusionNodeHiddenInIndexRector::class);
// setAccessRoles
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'setAccessRoles', '!! Node::setAccessRoles() is not supported by the new CR.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setAccessRoles', '!! Node::setAccessRoles() is not supported by the new CR.');
// getAccessRoles
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getAccessRoles', '!! Node::getAccessRoles() is not supported by the new CR.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getAccessRoles', '!! Node::getAccessRoles() is not supported by the new CR.');
// getPath
$rectorConfig->rule(NodeGetPathRector::class);
// Fusion: .depth -> Neos.NodeAccess.depth(node)
Expand All @@ -149,16 +149,16 @@
// Fusion: .depth -> Neos.Node.depth(node)
$rectorConfig->rule(FusionNodeDepthRector::class);
// setWorkspace -> internal
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'setWorkspace', '!! Node::setWorkspace() was always internal, and the workspace system has been fundamentally changed with the new CR. Try to rewrite your code around Content Streams.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setWorkspace', '!! Node::setWorkspace() was always internal, and the workspace system has been fundamentally changed with the new CR. Try to rewrite your code around Content Streams.');
// getWorkspace
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.');
// getIdentifier
$rectorConfig->rule(NodeGetIdentifierRector::class);
$rectorConfig->rule(FusionNodeIdentifierRector::class);
// setIndex -> internal
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'setIndex', '!! Node::setIndex() was always internal. To reorder nodes, use the "MoveNodeAggregate" command');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'setIndex', '!! Node::setIndex() was always internal. To reorder nodes, use the "MoveNodeAggregate" command');
// getIndex
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getIndex', '!! Node::getIndex() is not supported. You can fetch all siblings and inspect the ordering');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getIndex', '!! Node::getIndex() is not supported. You can fetch all siblings and inspect the ordering');
// getParent -> Node
$rectorConfig->rule(NodeGetParentRector::class);
// Fusion: .parent -> Neos.NodeAccess.findParent(node)
Expand All @@ -175,7 +175,7 @@
// remove()
// setRemoved()
// isRemoved()
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'isRemoved', '!! Node::isRemoved() - the new CR *never* returns removed nodes; so you can simplify your code and just assume removed == FALSE in all scenarios.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'isRemoved', '!! Node::isRemoved() - the new CR *never* returns removed nodes; so you can simplify your code and just assume removed == FALSE in all scenarios.');
$fusionNodePropertyPathToWarningComments[] = new FusionNodePropertyPathToWarningComment('removed', 'Line %LINE: !! node.removed - the new CR *never* returns removed nodes; so you can simplify your code and just assume removed == FALSE in all scenarios.');
// isVisible()
// isAccessible()
Expand All @@ -188,7 +188,7 @@
// copyAfter()
// copyInto()
// getNodeData()
$methodCallToWarningComments[] = new MethodCallToWarningComment(Node::class, 'getNodeData', '!! Node::getNodeData() - the new CR is not based around the concept of NodeData anymore. You need to rewrite your code here.');
$methodCallToWarningComments[] = new MethodCallToWarningComment(NodeLegacyStub::class, 'getNodeData', '!! Node::getNodeData() - the new CR is not based around the concept of NodeData anymore. You need to rewrite your code here.');
// getContext()
// getContext()->getWorkspace()
$rectorConfig->rule(NodeGetContextGetWorkspaceRector::class);
Expand All @@ -210,13 +210,13 @@
// isTethered()
// getContentStreamIdentifier() -> threw exception in <= Neos 8.0 - so nobody could have used this
// getNodeAggregateIdentifier()
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getNodeAggregateIdentifier', 'nodeAggregateId');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getNodeAggregateIdentifier', 'nodeAggregateId');
$rectorConfig->rule(rectorClass: FusionNodeAggregateIdentifierRector::class);
// getNodeTypeName()
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getNodeTypeName', 'nodeTypeName');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getNodeTypeName', 'nodeTypeName');
// getNodeType() ** (included/compatible in old NodeInterface)
// getNodeName()
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(Node::class, 'getNodeName', 'nodeName');
$methodCallToPropertyFetches[] = new MethodCallToPropertyFetch(NodeLegacyStub::class, 'getNodeName', 'nodeName');
// getOriginDimensionSpacePoint() -> threw exception in <= Neos 8.0 - so nobody could have used this
// getProperties() ** (included/compatible in old NodeInterface)
// getProperty() ** (included/compatible in old NodeInterface)
Expand Down Expand Up @@ -383,7 +383,7 @@
]);

$rectorConfig->ruleWithConfiguration(RenameClassRector::class, [
LegacyContextStub::class => Node::class,
LegacyContextStub::class => NodeLegacyStub::class,
]);

// Should run LAST - as other rules above might create $this->contentRepositoryRegistry calls.
Expand Down
3 changes: 3 additions & 0 deletions src/ContentRepository90/Legacy/NodeLegacyStub.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

namespace Neos\Rector\ContentRepository90\Legacy;

/**
* @deprecated
*/
class NodeLegacyStub
{

Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeFindParentNodeRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'findParentNode')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetChildNodesRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getChildNodes')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (!$this->isObjectType($node->var->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function refactor(Node $node): ?Node
return null;
}

if (!$this->isObjectType($node->var->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetDepthRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getDepth')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetDimensionsRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getDimensions')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetIdentifierRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function refactor(Node $node): ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getIdentifier')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetParentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getParent')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeGetPathRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'getPath')) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'isHiddenInIndex')) {
Expand Down
2 changes: 1 addition & 1 deletion src/ContentRepository90/Rules/NodeIsHiddenRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function refactor(Node $node) : ?Node
{
assert($node instanceof Node\Expr\MethodCall);

if (!$this->isObjectType($node->var, new ObjectType(\Neos\ContentRepository\Core\Projection\ContentGraph\Node::class))) {
if (!$this->isObjectType($node->var, new ObjectType(\Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub::class))) {
return null;
}
if (!$this->isName($node->name, 'isHidden')) {
Expand Down
3 changes: 2 additions & 1 deletion src/Generic/Rules/MethodCallToWarningCommentRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Webmozart\Assert\Assert;
use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub;

final class MethodCallToWarningCommentRector extends AbstractRector implements ConfigurableRectorInterface
{
Expand All @@ -32,7 +33,7 @@ public function __construct(
public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('"Warning comments for various non-supported use cases', __CLASS__, [
new MethodCallToWarningComment(Node::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.')
new MethodCallToWarningComment(NodeLegacyStub::class, 'getWorkspace', '!! Node::getWorkspace() does not make sense anymore concept-wise. In Neos < 9, it pointed to the workspace where the node was *at home at*. Now, the closest we have here is the node identity.')
]);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<?php

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub;

class SomeClass
{
public function run(Node $node)
public function run(NodeLegacyStub $node)
{
$parentNode = $node->findParentNode();
}
Expand All @@ -14,11 +14,11 @@ class SomeClass
-----
<?php

use Neos\ContentRepository\Core\Projection\ContentGraph\Node;
use Neos\Rector\ContentRepository90\Legacy\NodeLegacyStub;

class SomeClass
{
public function run(Node $node)
public function run(NodeLegacyStub $node)
{
$subgraph = $this->contentRepositoryRegistry->subgraphForNode($node);
$parentNode = $subgraph->findParentNode($node->nodeAggregateId);
Expand Down
Loading

0 comments on commit 70bd4c5

Please sign in to comment.