Skip to content

Commit f6eabfe

Browse files
authored
chore(reflection): cleanup memoization trait (#1336)
1 parent 0199fa3 commit f6eabfe

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

packages/reflection/src/ClassReflector.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Tempest\Reflection;
66

7+
use Closure;
78
use ReflectionClass as PHPReflectionClass;
89
use ReflectionMethod as PHPReflectionMethod;
910
use ReflectionProperty as PHPReflectionProperty;
@@ -14,7 +15,8 @@
1415
final class ClassReflector implements Reflector
1516
{
1617
use HasAttributes;
17-
use HasMemoization;
18+
19+
private array $memoize = [];
1820

1921
private readonly PHPReflectionClass $reflectionClass;
2022

@@ -167,4 +169,13 @@ public function implements(string $interface): bool
167169
{
168170
return $this->isInstantiable() && $this->getType()->matches($interface);
169171
}
172+
173+
private function memoize(string $key, Closure $closure): mixed
174+
{
175+
if (! isset($this->memoize[$key])) {
176+
$this->memoize[$key] = $closure();
177+
}
178+
179+
return $this->memoize[$key];
180+
}
170181
}

packages/reflection/src/HasAttributes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313

1414
trait HasAttributes
1515
{
16-
use HasMemoization;
17-
1816
abstract public function getReflection(): PHPReflectionClass|PHPReflectionMethod|PHPReflectionProperty|PHPReflectionParameter;
1917

2018
/**

packages/reflection/src/HasMemoization.php

Lines changed: 0 additions & 19 deletions
This file was deleted.

0 commit comments

Comments
 (0)