diff --git a/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php b/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php index 569644955f64..86b248f56f5c 100644 --- a/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php +++ b/rules/php74/src/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector.php @@ -10,7 +10,6 @@ use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Ternary; use PhpParser\Node\Expr\Variable; -use PhpParser\Node\Stmt\Return_; use Rector\Core\Rector\AbstractRector; use Rector\Core\RectorDefinition\CodeSample; use Rector\Core\RectorDefinition\RectorDefinition; @@ -168,16 +167,8 @@ private function shouldSkipMethodCall(MethodCall $methodCall): bool if ($parentNode instanceof String_) { return false; } - - if ($parentNode instanceof Concat) { - return false; - } - // probably already converted - if ($parentNode instanceof Ternary) { - return true; - } - return $parentNode instanceof Return_; + return ! $parentNode instanceof Concat; } private function isReflectionParameterGetTypeMethodCall(MethodCall $methodCall): bool diff --git a/rules/php74/tests/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector/Fixture/skip_non_to_string.php.inc b/rules/php74/tests/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector/Fixture/skip_non_to_string.php.inc new file mode 100644 index 000000000000..3057185ad649 --- /dev/null +++ b/rules/php74/tests/Rector/MethodCall/ChangeReflectionTypeToStringToGetNameRector/Fixture/skip_non_to_string.php.inc @@ -0,0 +1,18 @@ +getType(); + if ($parameterType !== null) { + /** @var ReflectionType $parameterType */ + $parameterType = $parameterType->getName(); + } + } +}