Skip to content

Commit

Permalink
[TASK] Improve other Rectors by reusing removeArrayItemFromArrayByKey
Browse files Browse the repository at this point in the history
  • Loading branch information
simonschaufi committed Nov 16, 2023
1 parent be293f6 commit c7ade09
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 80 deletions.
10 changes: 5 additions & 5 deletions src/Helper/TcaHelperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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<string, Node>
*/
Expand Down
16 changes: 2 additions & 14 deletions src/Rector/v10/v0/RemoveSeliconFieldPathRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
Expand Down
16 changes: 2 additions & 14 deletions src/Rector/v10/v0/RemoveTcaOptionSetToDefaultOnCopyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -18,8 +16,6 @@
*/
final class RemoveEnableMultiSelectFilterTextfieldRector extends AbstractTcaRector
{
use TcaHelperTrait;

/**
* @codeCoverageIgnore
*/
Expand Down Expand Up @@ -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;
}
}
Expand Down
17 changes: 2 additions & 15 deletions src/Rector/v10/v3/RemoveExcludeOnTransOrigPointerFieldRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down

0 comments on commit c7ade09

Please sign in to comment.