Node too free types fixes

This commit is contained in:
TomasVotruba 2017-09-09 20:59:16 +02:00
parent dfa47b493e
commit 480381bbe1
2 changed files with 28 additions and 0 deletions

View File

@ -2,6 +2,7 @@
namespace Rector\NodeTypeResolver;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
@ -100,6 +101,10 @@ final class TypeContext
return null;
}
if ($functionLikeNode instanceof Closure) {
return null;
}
$methodName = (string) $functionLikeNode->name;
return new ReflectionMethod($className, $methodName);

View File

@ -5,8 +5,10 @@ namespace Rector\NodeTypeResolver\TypesExtractor;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use ReflectionClass;
final class ConstructorPropertyTypesExtractor
@ -68,6 +70,14 @@ final class ConstructorPropertyTypesExtractor
private function isAssignThisNode(Node $node): bool
{
if (! $node instanceof Expression) {
return false;
}
if ($this->isParentConstructCall($node)) {
return false;
}
if (! $node->expr instanceof Assign) {
return false;
}
@ -106,4 +116,17 @@ final class ConstructorPropertyTypesExtractor
return $propertiesWithTypes;
}
private function isParentConstructCall(Node $node): bool
{
if (! $node instanceof Expression) {
return false;
}
if (! $node->expr instanceof StaticCall) {
return false;
}
return $node->expr->name === '__construct';
}
}