|
6 | 6 | use PhpParser\Node\FunctionLike; |
7 | 7 | use PhpParser\Node\Stmt\Class_; |
8 | 8 | use PhpParser\Node\Stmt\ClassLike; |
| 9 | +use PhpParser\Node\Stmt\ClassMethod; |
| 10 | +use PhpParser\Node\Stmt\Function_; |
9 | 11 | use Rector\BetterReflection\Reflector\MethodReflector; |
10 | 12 | use Rector\NodeTypeResolver\TypesExtractor\ConstructorPropertyTypesExtractor; |
11 | | -use ReflectionFunction; |
| 13 | +use Roave\BetterReflection\Reflection\ReflectionFunction; |
12 | 14 | use Roave\BetterReflection\Reflection\ReflectionMethod; |
13 | 15 |
|
14 | 16 | /** |
@@ -100,21 +102,29 @@ public function addAssign(string $newVariable, string $oldVariable): void |
100 | 102 | } |
101 | 103 |
|
102 | 104 | /** |
103 | | - * @return \Roave\BetterReflection\Reflection\ReflectionFunction|ReflectionMethod|null |
| 105 | + * @param Function_|ClassMethod|Closure $functionLikeNode |
| 106 | + * |
| 107 | + * @return ReflectionFunction|ReflectionMethod|null |
104 | 108 | */ |
105 | 109 | private function getFunctionReflection(FunctionLike $functionLikeNode) |
106 | 110 | { |
107 | | - if ($this->classLikeNode) { |
108 | | - if ($functionLikeNode instanceof Closure) { |
109 | | - return null; |
110 | | - } |
| 111 | + if ($functionLikeNode instanceof Closure) { |
| 112 | + return null; |
| 113 | + } |
111 | 114 |
|
| 115 | + if ($this->classLikeNode) { |
112 | 116 | $className = $this->classLikeNode->namespacedName->toString(); |
113 | 117 | $methodName = (string) $functionLikeNode->name; |
114 | 118 |
|
115 | 119 | return $this->methodReflector->reflectClassMethod($className, $methodName); |
116 | 120 | } |
117 | 121 |
|
118 | | - return new ReflectionFunction((string) $functionLikeNode->name); |
| 122 | + /** @var Function_ $functionLikeNode */ |
| 123 | + $functionName = (string) $functionLikeNode->name; |
| 124 | + if (! function_exists($functionName)) { |
| 125 | + return null; |
| 126 | + } |
| 127 | + |
| 128 | + return ReflectionFunction::createFromName($functionName); |
119 | 129 | } |
120 | 130 | } |
0 commit comments