Fix Scalar_Encapsed node as dynamic in ExprAnalyzer::isDynamicExpr() (#2309)

* Add test to skip interpolated string conversion

* Fix Scalar_Encapsed node as dynamic in ExprAnalyzer::isDynamicExpr()
This commit is contained in:
USAMI Kenta 2022-05-14 11:36:09 +09:00 committed by GitHub
parent 26d2589aba
commit f92d5deca3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View File

@ -0,0 +1,13 @@
<?php
namespace Rector\Tests\CodeQuality\Rector\Class_\InlineConstructorDefaultToPropertyRector\Fixture;
final class SkipComplexAssign
{
private $name;
public function __construct($name)
{
$this->name = "interpolated {$name}";
}
}

View File

@ -13,6 +13,7 @@ use PhpParser\Node\FunctionLike;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Encapsed;
use PHPStan\PhpDocParser\Ast\PhpDoc\ParamTagValueNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Core\NodeManipulator\ArrayManipulator;
@ -68,7 +69,8 @@ final class ExprAnalyzer
{
if (! $expr instanceof Array_) {
if ($expr instanceof Scalar) {
return false;
// string interpolation is true, otherwise false
return $expr instanceof Encapsed;
}
return ! $this->isAllowedConstFetchOrClassConstFetch($expr);