mirror of https://github.com/rectorphp/rector.git
skip traits in CountOnNullRector
This commit is contained in:
parent
895f09b150
commit
6d0e77fe1a
|
@ -92,6 +92,7 @@ final class VariableTypeResolver implements NodeTypeResolverInterface
|
|||
private function resolveTypesFromScope(Variable $variable, string $variableName): Type
|
||||
{
|
||||
$nodeScope = $this->resolveNodeScope($variable);
|
||||
|
||||
if ($nodeScope === null) {
|
||||
return new MixedType();
|
||||
}
|
||||
|
@ -118,6 +119,7 @@ final class VariableTypeResolver implements NodeTypeResolverInterface
|
|||
/** @var string $traitName */
|
||||
$traitName = $variable->getAttribute(AttributeKey::CLASS_NAME);
|
||||
$traitNodeScope = $this->traitNodeScopeCollector->getScopeForTraitAndNode($traitName, $variable);
|
||||
|
||||
if ($traitNodeScope !== null) {
|
||||
return $traitNodeScope;
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use PhpParser\Node\Expr\Ternary;
|
|||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use PhpParser\Node\Scalar\LNumber;
|
||||
use PhpParser\Node\Stmt\Trait_;
|
||||
use PHPStan\Type\NullType;
|
||||
use Rector\Core\Rector\AbstractRector;
|
||||
use Rector\Core\RectorDefinition\CodeSample;
|
||||
|
@ -111,6 +112,16 @@ PHP
|
|||
return true;
|
||||
}
|
||||
|
||||
return ! isset($funcCall->args[0]);
|
||||
if (! isset($funcCall->args[0])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// skip node in trait, as impossible to analyse
|
||||
$classNode = $funcCall->getAttribute(AttributeKey::CLASS_NODE);
|
||||
if ($classNode instanceof Trait_) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,17 +4,16 @@ namespace Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector\Fixture;
|
|||
|
||||
use Rector\Php71\Tests\Rector\FuncCall\CountOnNullRector\Source\CountableClass;
|
||||
|
||||
class SomeClassUsingTrait
|
||||
{
|
||||
use VariableWithinTraitMethod;
|
||||
}
|
||||
|
||||
trait VariableWithinTraitMethod
|
||||
{
|
||||
public function run()
|
||||
{
|
||||
$array = [];
|
||||
$countable = new CountableClass();
|
||||
|
||||
return
|
||||
count($array)
|
||||
+
|
||||
count($countable)
|
||||
;
|
||||
return count($array);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,5 +11,3 @@ final class SkipParentDefinition implements SomeInterface
|
|||
return ['test', 'test2'];
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
|
Loading…
Reference in New Issue