-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathWorkspaceGetDescriptionRector.php
71 lines (60 loc) · 2 KB
/
WorkspaceGetDescriptionRector.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
declare (strict_types=1);
namespace Neos\Rector\ContentRepository90\Rules;
use Neos\Rector\Utility\CodeSampleLoader;
use PhpParser\Node;
use PhpParser\Node\Expr\Variable;
use PHPStan\Type\ObjectType;
use Rector\Core\Rector\AbstractRector;
use Rector\PostRector\Collector\NodesToAddCollector;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
use Neos\ContentRepository\Core\SharedModel\Workspace\Workspace;
final class WorkspaceGetDescriptionRector extends AbstractRector
{
use AllTraits;
public function __construct(
private readonly NodesToAddCollector $nodesToAddCollector,
)
{
}
public function getRuleDefinition(): RuleDefinition
{
return CodeSampleLoader::fromFile('"Workspace::getDescription()" 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(Workspace::class))) {
return null;
}
if (!$this->isName($node->name, 'getDescription')) {
return null;
}
$this->nodesToAddCollector->addNodesBeforeNode(
[
self::todoComment('Make this code aware of multiple Content Repositories.')
],
$node
);
return
$this->nodeFactory->createPropertyFetch(
$this->nodeFactory->createPropertyFetch(
$this->this_workspaceService_getWorkspaceMetadata(
$this->contentRepositoryId_fromString('default'),
$this->nodeFactory->createPropertyFetch($node->var, 'workspaceName')
),
'description',
), 'value'
);
}
}