|
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,37 @@ 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 | + if ($this->reflectionByHash[$callLikeHash] ?? null) { |
| 207 | + return $this->reflectionByHash[$callLikeHash]; |
| 208 | + } |
| 209 | + |
199 | 210 | if ($callLike instanceof MethodCall) { |
200 | | - return $this->resolveMethodReflectionFromMethodCall($callLike); |
| 211 | + $reflection = $this->resolveMethodReflectionFromMethodCall($callLike); |
| 212 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 213 | + |
| 214 | + return $reflection; |
201 | 215 | } |
202 | 216 |
|
203 | 217 | if ($callLike instanceof StaticCall) { |
204 | | - return $this->resolveMethodReflectionFromStaticCall($callLike); |
| 218 | + $reflection = $this->resolveMethodReflectionFromStaticCall($callLike); |
| 219 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 220 | + return $reflection; |
205 | 221 | } |
206 | 222 |
|
207 | 223 | if ($callLike instanceof New_) { |
208 | | - return $this->resolveMethodReflectionFromNew($callLike); |
| 224 | + $reflection = $this->resolveMethodReflectionFromNew($callLike); |
| 225 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 226 | + return $reflection; |
209 | 227 | } |
210 | 228 |
|
211 | 229 | if ($callLike instanceof FuncCall) { |
212 | | - return $this->resolveFunctionReflectionFromFuncCall($callLike); |
| 230 | + $reflection = $this->resolveFunctionReflectionFromFuncCall($callLike); |
| 231 | + $this->reflectionByHash[$callLikeHash] = $reflection; |
| 232 | + return $reflection; |
213 | 233 | } |
214 | 234 |
|
215 | | - // todo: support NullsafeMethodCall |
216 | 235 | return null; |
217 | 236 | } |
218 | 237 |
|
|
0 commit comments