-
-
Notifications
You must be signed in to change notification settings - Fork 63
/
RemoveTCAInterfaceAlwaysDescriptionRector.php
69 lines (60 loc) · 2.07 KB
/
RemoveTCAInterfaceAlwaysDescriptionRector.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
<?php
declare(strict_types=1);
namespace Ssch\TYPO3Rector\TYPO312\v0;
use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use Ssch\TYPO3Rector\Rector\AbstractTcaRector;
use Symplify\RuleDocGenerator\Contract\DocumentedRuleInterface;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
/**
* @changelog https://docs.typo3.org/c/typo3/cms-core/main/en-us/Changelog/12.0/Breaking-97312-RemoveContextSensitiveHelp.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveTCAInterfaceAlwaysDescriptionRector\RemoveTCAInterfaceAlwaysDescriptionRectorTest
*/
final class RemoveTCAInterfaceAlwaysDescriptionRector extends AbstractTcaRector implements DocumentedRuleInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition("Remove ['interface']['always_description']", [new CodeSample(
<<<'CODE_SAMPLE'
return [
'interface' => [
'always_description' => 'foo,bar,baz',
],
'columns' => [
],
];
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
return [
'columns' => [
],
];
CODE_SAMPLE
)]);
}
protected function refactorInterface(Array_ $interfaceArray, Node $node): void
{
$interfaceItems = $interfaceArray;
$remainingInterfaceItems = count($interfaceItems->items);
foreach ($interfaceItems->items as $interfaceItemKey => $interfaceItem) {
if (! $interfaceItem instanceof ArrayItem) {
continue;
}
if (! $interfaceItem->key instanceof Expr) {
continue;
}
if ($this->valueResolver->isValue($interfaceItem->key, 'always_description')) {
unset($interfaceItems->items[$interfaceItemKey]);
--$remainingInterfaceItems;
break;
}
}
if ($remainingInterfaceItems === 0 && $node instanceof Array_) {
$this->removeArrayItemFromArrayByKey($node, 'interface');
}
}
}