Skip to content

Commit fde29a5

Browse files
canvuralondrejmirtes
authored andcommitted
feat: cache the result of ClassReflection::hasMethod method
1 parent 14faee1 commit fde29a5

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Reflection/ClassReflection.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ class ClassReflection
142142
/** @var array<string, true> */
143143
private static array $resolvingTypeAliasImports = [];
144144

145+
/** @var array<string, bool> */
146+
private array $hasMethodCache = [];
147+
145148
/**
146149
* @param PropertiesClassReflectionExtension[] $propertiesClassReflectionExtensions
147150
* @param MethodsClassReflectionExtension[] $methodsClassReflectionExtensions
@@ -482,16 +485,26 @@ public function hasProperty(string $propertyName): bool
482485

483486
public function hasMethod(string $methodName): bool
484487
{
488+
if (array_key_exists($methodName, $this->hasMethodCache)) {
489+
return $this->hasMethodCache[$methodName];
490+
}
491+
485492
foreach ($this->methodsClassReflectionExtensions as $extension) {
486493
if ($extension->hasMethod($this, $methodName)) {
494+
$this->hasMethodCache[$methodName] = true;
495+
487496
return true;
488497
}
489498
}
490499

491500
if ($this->requireExtendsMethodsClassReflectionExtension->hasMethod($this, $methodName)) {
501+
$this->hasMethodCache[$methodName] = true;
502+
492503
return true;
493504
}
494505

506+
$this->hasMethodCache[$methodName] = false;
507+
495508
return false;
496509
}
497510

0 commit comments

Comments
 (0)