TypeContext: do not reflect non-loaded functions

This commit is contained in:
TomasVotruba 2017-09-28 19:51:06 +02:00
parent 596b5b436e
commit e358f71b77
2 changed files with 19 additions and 9 deletions

View File

@ -6,9 +6,11 @@ use PhpParser\Node\Expr\Closure;
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use Rector\BetterReflection\Reflector\MethodReflector;
use Rector\NodeTypeResolver\TypesExtractor\ConstructorPropertyTypesExtractor;
use ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionFunction;
use Roave\BetterReflection\Reflection\ReflectionMethod;
/**
@ -100,21 +102,29 @@ final class TypeContext
}
/**
* @return \Roave\BetterReflection\Reflection\ReflectionFunction|ReflectionMethod|null
* @param Function_|ClassMethod|Closure $functionLikeNode
*
* @return ReflectionFunction|ReflectionMethod|null
*/
private function getFunctionReflection(FunctionLike $functionLikeNode)
{
if ($this->classLikeNode) {
if ($functionLikeNode instanceof Closure) {
return null;
}
if ($functionLikeNode instanceof Closure) {
return null;
}
if ($this->classLikeNode) {
$className = $this->classLikeNode->namespacedName->toString();
$methodName = (string) $functionLikeNode->name;
return $this->methodReflector->reflectClassMethod($className, $methodName);
}
return new ReflectionFunction((string) $functionLikeNode->name);
/** @var Function_ $functionLikeNode */
$functionName = (string) $functionLikeNode->name;
if (! function_exists($functionName)) {
return null;
}
return ReflectionFunction::createFromName($functionName);
}
}

View File

@ -67,12 +67,12 @@ final class ProcessCommand extends Command
$this->ensureSomeRectorsAreRegistered();
$this->reportLoadedRectors();
$files = $this->findPhpFilesInDirectories($source);
$this->reportFoundFiles($files);
$this->reportLoadedRectors();
$this->fileProcessor->processFiles($files);
return 0;