|
37 | 37 | use Rector\StaticTypeMapper\ValueObject\Type\ShortenedObjectType; |
38 | 38 | use Rector\ValueObject\MethodName; |
39 | 39 |
|
40 | | -final readonly class ReflectionResolver |
| 40 | +final class ReflectionResolver |
41 | 41 | { |
| 42 | + /** |
| 43 | + * @var array<string, MethodReflection|FunctionReflection|null> |
| 44 | + */ |
| 45 | + private array $reflectionByHash = []; |
| 46 | + |
42 | 47 | public function __construct( |
43 | | - private ReflectionProvider $reflectionProvider, |
44 | | - private NodeTypeResolver $nodeTypeResolver, |
45 | | - private NodeNameResolver $nodeNameResolver, |
46 | | - private ClassAnalyzer $classAnalyzer, |
47 | | - private MethodReflectionResolver $methodReflectionResolver |
| 48 | + private readonly ReflectionProvider $reflectionProvider, |
| 49 | + private readonly NodeTypeResolver $nodeTypeResolver, |
| 50 | + private readonly NodeNameResolver $nodeNameResolver, |
| 51 | + private readonly ClassAnalyzer $classAnalyzer, |
| 52 | + private readonly MethodReflectionResolver $methodReflectionResolver |
48 | 53 | ) { |
49 | 54 | } |
50 | 55 |
|
@@ -196,23 +201,36 @@ public function resolveMethodReflectionFromMethodCall(MethodCall $methodCall): ? |
196 | 201 | public function resolveFunctionLikeReflectionFromCall( |
197 | 202 | CallLike $callLike |
198 | 203 | ): MethodReflection | FunctionReflection | null { |
| 204 | + // cache here |
| 205 | + $callLikeHash = spl_object_hash($callLike); |
| 206 | + |
| 207 | + if (isset($this->reflectionByHash[$callLikeHash])) { |
| 208 | + return $this->reflectionByHash[$callLikeHash]; |
| 209 | + } |
| 210 | + |
199 | 211 | if ($callLike instanceof MethodCall) { |
200 | | - return $this->resolveMethodReflectionFromMethodCall($callLike); |
| 212 | + $reflection = $this->resolveMethodReflectionFromMethodCall($callLike); |
| 213 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 214 | + |
| 215 | + return $reflection; |
201 | 216 | } |
202 | 217 |
|
203 | 218 | if ($callLike instanceof StaticCall) { |
204 | | - return $this->resolveMethodReflectionFromStaticCall($callLike); |
| 219 | + $reflection = $this->resolveMethodReflectionFromStaticCall($callLike); |
| 220 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 221 | + return $reflection; |
205 | 222 | } |
206 | 223 |
|
207 | 224 | if ($callLike instanceof New_) { |
208 | | - return $this->resolveMethodReflectionFromNew($callLike); |
| 225 | + $reflection = $this->resolveMethodReflectionFromNew($callLike); |
| 226 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 227 | + return $reflection; |
209 | 228 | } |
210 | 229 |
|
211 | 230 | if ($callLike instanceof FuncCall) { |
212 | 231 | return $this->resolveFunctionReflectionFromFuncCall($callLike); |
213 | 232 | } |
214 | 233 |
|
215 | | - // todo: support NullsafeMethodCall |
216 | 234 | return null; |
217 | 235 | } |
218 | 236 |
|
|
0 commit comments