-
-
Notifications
You must be signed in to change notification settings - Fork 62
/
Copy pathRemoveCruserIdRector.php
65 lines (58 loc) · 1.71 KB
/
RemoveCruserIdRector.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
<?php
declare(strict_types=1);
namespace Ssch\TYPO3Rector\TYPO312\v0;
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-98024-TCA-option-cruserid-removed.html
* @see \Ssch\TYPO3Rector\Tests\Rector\v12\v0\tca\RemoveCruserIdRector\RemoveCruserIdRectorTest
*/
final class RemoveCruserIdRector extends AbstractTcaRector implements DocumentedRuleInterface
{
public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Remove the TCA option cruser_id', [new CodeSample(
<<<'CODE_SAMPLE'
return [
'ctrl' => [
'label' => 'foo',
'cruser_id' => 'cruser_id',
],
'columns' => [
],
];
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
return [
'ctrl' => [
'label' => 'foo',
],
'columns' => [
],
];
CODE_SAMPLE
)]);
}
protected function refactorCtrl(Array_ $ctrlArray): void
{
foreach ($ctrlArray->items as $ctrlItemKey => $ctrlItem) {
if (! $ctrlItem instanceof ArrayItem) {
continue;
}
if (! $ctrlItem->key instanceof Expr) {
continue;
}
if ($this->valueResolver->isValue($ctrlItem->key, 'cruser_id')) {
unset($ctrlArray->items[$ctrlItemKey]);
$this->hasAstBeenChanged = true;
break;
}
}
}
}