Skip to content

Commit

Permalink
[CodeQuality] Remove direct return STOP_TRAVERSAL on SetTypeToCastRec…
Browse files Browse the repository at this point in the history
…tor (#4187)
  • Loading branch information
samsonasik authored Jun 12, 2023
1 parent 5612c7f commit 7a61135
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion rules/CodeQuality/Rector/FuncCall/SetTypeToCastRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ final class SetTypeToCastRector extends AbstractRector
'string' => String_::class,
];

/**
* @var string
*/
private const IS_ARG_VALUE_ITEM_SET_TYPE = 'is_arg_value_item_set_type';

public function getRuleDefinition(): RuleDefinition
{
return new RuleDefinition('Changes settype() to (type) where possible', [
Expand Down Expand Up @@ -91,7 +96,7 @@ public function refactor(Node $node)
{
if ($node instanceof Arg || $node instanceof ArrayItem) {
if ($this->isSetTypeFuncCall($node->value)) {
return NodeTraverser::STOP_TRAVERSAL;
$node->value->setAttribute(self::IS_ARG_VALUE_ITEM_SET_TYPE, true);
}

return null;
Expand Down Expand Up @@ -126,6 +131,10 @@ private function refactorFuncCall(FuncCall $funcCall, bool $isStandaloneExpressi
return null;
}

if ($funcCall->getAttribute(self::IS_ARG_VALUE_ITEM_SET_TYPE) === true) {
return null;
}

$typeValue = $this->valueResolver->getValue($funcCall->getArgs()[1]->value);
if (! is_string($typeValue)) {
return null;
Expand Down

0 comments on commit 7a61135

Please sign in to comment.