-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #96 from neos/feature/improve-node-rewrite-v2
FEATURE: Improve Node and Node interfaces rewrites (part 2)
- Loading branch information
Showing
23 changed files
with
820 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/ContentRepository90/Rules/NodeGetContextPathRector.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
|
||
namespace Neos\Rector\ContentRepository90\Rules; | ||
|
||
use Neos\ContentRepository\Core\SharedModel\Node\NodeAddress; | ||
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; | ||
|
||
final class NodeGetContextPathRector extends AbstractRector | ||
{ | ||
use AllTraits; | ||
|
||
public function __construct( | ||
private readonly NodesToAddCollector $nodesToAddCollector | ||
) { | ||
} | ||
|
||
public function getRuleDefinition(): RuleDefinition | ||
{ | ||
return CodeSampleLoader::fromFile('"NodeInterface::getContextPath()" will be rewritten', __CLASS__); | ||
} | ||
|
||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
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, 'getContextPath')) { | ||
return null; | ||
} | ||
|
||
|
||
return | ||
$this->nodeFactory->createMethodCall( | ||
$this->nodeFactory->createStaticCall( | ||
NodeAddress::class, | ||
'fromNode', | ||
[$node->var]), | ||
'toJson' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.