From 8d38c1bfc1b956592e25c18aa64cfee3658019fe Mon Sep 17 00:00:00 2001 From: Simon Schaufelberger Date: Thu, 16 Nov 2023 23:15:29 +0100 Subject: [PATCH] [TASK] Improve other Rectors by reusing removeArrayItemFromArrayByKey --- src/Helper/TcaHelperTrait.php | 10 ++--- .../v10/v0/RemoveSeliconFieldPathRector.php | 16 +------- ...emoveTcaOptionSetToDefaultOnCopyRector.php | 16 +------- ...EnableMultiSelectFilterTextfieldRector.php | 14 +------ ...veExcludeOnTransOrigPointerFieldRector.php | 17 +------- ...dFieldListInsideInterfaceSectionRector.php | 17 +------- .../MigrateColsToSizeForTcaTypeNoneRector.php | 5 +-- .../Fixture/fixture_no_change.php.inc | 41 ------------------- 8 files changed, 15 insertions(+), 121 deletions(-) delete mode 100644 tests/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector/Fixture/fixture_no_change.php.inc diff --git a/src/Helper/TcaHelperTrait.php b/src/Helper/TcaHelperTrait.php index 847046d6b..82206fb27 100644 --- a/src/Helper/TcaHelperTrait.php +++ b/src/Helper/TcaHelperTrait.php @@ -132,6 +132,11 @@ protected function isConfigType(Array_ $columnItemConfigurationArray, string $ty return $this->hasKeyValuePair($columnItemConfigurationArray, 'type', $type); } + protected function configIsOfRenderType(Array_ $configValueArray, string $expectedRenderType): bool + { + return $this->hasKeyValuePair($configValueArray, 'renderType', $expectedRenderType); + } + private function isInlineType(Array_ $columnItemConfigurationArray): bool { return $this->isConfigType($columnItemConfigurationArray, 'inline'); @@ -192,11 +197,6 @@ private function configIsOfInternalType(Array_ $configValueArray, string $expect return $this->hasKeyValuePair($configValueArray, 'internal_type', $expectedType); } - private function configIsOfRenderType(Array_ $configValueArray, string $expectedRenderType): bool - { - return $this->hasKeyValuePair($configValueArray, 'renderType', $expectedRenderType); - } - /** * @return Generator */ diff --git a/src/Rector/v10/v0/RemoveSeliconFieldPathRector.php b/src/Rector/v10/v0/RemoveSeliconFieldPathRector.php index cdff29ccb..e02231dfe 100644 --- a/src/Rector/v10/v0/RemoveSeliconFieldPathRector.php +++ b/src/Rector/v10/v0/RemoveSeliconFieldPathRector.php @@ -5,7 +5,6 @@ namespace Ssch\TYPO3Rector\Rector\v10\v0; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Stmt\Return_; @@ -52,19 +51,8 @@ public function refactor(Node $node): ?Node } $hasAstBeenChanged = false; - foreach ($items->items as $fieldValue) { - if (! $fieldValue instanceof ArrayItem) { - continue; - } - - if (! $fieldValue->key instanceof Expr) { - continue; - } - - if ($this->valueResolver->isValue($fieldValue->key, 'selicon_field_path')) { - $this->removeNode($fieldValue); - $hasAstBeenChanged = true; - } + if ($this->removeArrayItemFromArrayByKey($items, 'selicon_field_path')) { + $hasAstBeenChanged = true; } return $hasAstBeenChanged ? $node : null; diff --git a/src/Rector/v10/v0/RemoveTcaOptionSetToDefaultOnCopyRector.php b/src/Rector/v10/v0/RemoveTcaOptionSetToDefaultOnCopyRector.php index 1b9e271d2..31f8ddc75 100644 --- a/src/Rector/v10/v0/RemoveTcaOptionSetToDefaultOnCopyRector.php +++ b/src/Rector/v10/v0/RemoveTcaOptionSetToDefaultOnCopyRector.php @@ -5,7 +5,6 @@ namespace Ssch\TYPO3Rector\Rector\v10\v0; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Stmt\Return_; @@ -52,19 +51,8 @@ public function refactor(Node $node): ?Node } $hasAstBeenChanged = false; - foreach ($items->items as $fieldValue) { - if (! $fieldValue instanceof ArrayItem) { - continue; - } - - if (! $fieldValue->key instanceof Expr) { - continue; - } - - if ($this->valueResolver->isValue($fieldValue->key, 'setToDefaultOnCopy')) { - $this->removeNode($fieldValue); - $hasAstBeenChanged = true; - } + if ($this->removeArrayItemFromArrayByKey($items, 'setToDefaultOnCopy')) { + $hasAstBeenChanged = true; } return $hasAstBeenChanged ? $node : null; diff --git a/src/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector.php b/src/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector.php index 53a57d3af..d3bf4e930 100644 --- a/src/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector.php +++ b/src/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector.php @@ -6,8 +6,6 @@ use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; -use Ssch\TYPO3Rector\Helper\TcaHelperTrait; use Ssch\TYPO3Rector\Rector\Tca\AbstractTcaRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; @@ -18,8 +16,6 @@ */ final class RemoveEnableMultiSelectFilterTextfieldRector extends AbstractTcaRector { - use TcaHelperTrait; - /** * @codeCoverageIgnore */ @@ -60,15 +56,7 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void return; } - $toRemoveArrayItem = $this->extractArrayItemByKey($configArray, 'enableMultiSelectFilterTextfield'); - if (! $toRemoveArrayItem instanceof ArrayItem || ! $toRemoveArrayItem->value instanceof Expr) { - return; - } - - $nodeValue = $this->valueResolver->getValue($toRemoveArrayItem->value); - - if ($nodeValue === true) { - $this->removeNode($toRemoveArrayItem); + if ($this->removeArrayItemFromArrayByKey($configArray, 'enableMultiSelectFilterTextfield')) { $this->hasAstBeenChanged = true; } } diff --git a/src/Rector/v10/v3/RemoveExcludeOnTransOrigPointerFieldRector.php b/src/Rector/v10/v3/RemoveExcludeOnTransOrigPointerFieldRector.php index 5d380c982..d17a29a1d 100644 --- a/src/Rector/v10/v3/RemoveExcludeOnTransOrigPointerFieldRector.php +++ b/src/Rector/v10/v3/RemoveExcludeOnTransOrigPointerFieldRector.php @@ -100,21 +100,8 @@ public function refactor(Node $node): ?Node continue; } - foreach ($columnItem->value->items as $configValue) { - if (! $configValue instanceof ArrayItem) { - continue; - } - - if (! $configValue->key instanceof Expr) { - continue; - } - - $configFieldName = $this->valueResolver->getValue($configValue->key); - - if ($configFieldName === 'exclude') { - $this->removeNode($configValue); - $hasAstBeenChanged = true; - } + if ($this->removeArrayItemFromArrayByKey($columnItem->value, 'exclude')) { + $hasAstBeenChanged = true; } } diff --git a/src/Rector/v10/v3/RemoveShowRecordFieldListInsideInterfaceSectionRector.php b/src/Rector/v10/v3/RemoveShowRecordFieldListInsideInterfaceSectionRector.php index d5d24960d..9a429b2d1 100644 --- a/src/Rector/v10/v3/RemoveShowRecordFieldListInsideInterfaceSectionRector.php +++ b/src/Rector/v10/v3/RemoveShowRecordFieldListInsideInterfaceSectionRector.php @@ -5,7 +5,6 @@ namespace Ssch\TYPO3Rector\Rector\v10\v3; use PhpParser\Node; -use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Stmt\Return_; @@ -54,20 +53,8 @@ public function refactor(Node $node): ?Node $remainingInterfaceItems = count($interfaceItems->items); - foreach ($interfaceItems->items as $interfaceItem) { - if (! $interfaceItem instanceof ArrayItem) { - continue; - } - - if (! $interfaceItem->key instanceof Expr) { - continue; - } - - if ($this->valueResolver->isValue($interfaceItem->key, 'showRecordFieldList')) { - $this->removeNode($interfaceItem); - --$remainingInterfaceItems; - break; - } + if ($this->removeArrayItemFromArrayByKey($interfaceItems, 'showRecordFieldList')) { + --$remainingInterfaceItems; } if ($remainingInterfaceItems === 0) { diff --git a/src/Rector/v12/v0/tca/MigrateColsToSizeForTcaTypeNoneRector.php b/src/Rector/v12/v0/tca/MigrateColsToSizeForTcaTypeNoneRector.php index 8f261de49..6ce5c753b 100644 --- a/src/Rector/v12/v0/tca/MigrateColsToSizeForTcaTypeNoneRector.php +++ b/src/Rector/v12/v0/tca/MigrateColsToSizeForTcaTypeNoneRector.php @@ -67,10 +67,7 @@ protected function refactorColumn(Expr $columnName, Expr $columnTca): void return; } - $arrayItemToRemove = $this->extractArrayItemByKey($configArray, 'size'); - if ($arrayItemToRemove instanceof ArrayItem) { - $this->removeNode($arrayItemToRemove); - } + $this->removeArrayItemFromArrayByKey($configArray, 'size'); $arrayItemToChange->key = new String_('size'); diff --git a/tests/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector/Fixture/fixture_no_change.php.inc b/tests/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector/Fixture/fixture_no_change.php.inc deleted file mode 100644 index 8f1bbe10d..000000000 --- a/tests/Rector/v10/v1/RemoveEnableMultiSelectFilterTextfieldRector/Fixture/fixture_no_change.php.inc +++ /dev/null @@ -1,41 +0,0 @@ - [ - ], - 'columns' => [ - 'foo' => [ - 'label' => 'foo', - 'config' => [ - 'type' => 'select', - 'renderType' => 'selectMultipleSideBySide', - 'enableMultiSelectFilterTextfield' => false, - ], - ], - ], -]; - -?> ------ - [ - ], - 'columns' => [ - 'foo' => [ - 'label' => 'foo', - 'config' => [ - 'type' => 'select', - 'renderType' => 'selectMultipleSideBySide', - 'enableMultiSelectFilterTextfield' => false, - ], - ], - ], -]; - -?>