Total Complexity | 4 |
Total Lines | 28 |
Duplicated Lines | 0 % |
Coverage | 90% |
Changes | 0 |
1 | <?php |
||
8 | abstract class DiscoveryCache |
||
9 | { |
||
10 | /** @var array */ |
||
11 | private static $cache = []; |
||
12 | |||
13 | 6 | protected static function makeInstance(string $interface) |
|
14 | { |
||
15 | 6 | if (! isset(self::$cache[$interface])) { |
|
16 | 6 | $implementation = static::locate($interface); |
|
17 | 6 | self::$cache[$interface] = new $implementation(); |
|
18 | } |
||
19 | |||
20 | 6 | return self::$cache[$interface]; |
|
21 | } |
||
22 | |||
23 | 6 | public static function clearCache(?string $interface = null): void |
|
29 | } |
||
30 | 6 | } |
|
31 | |||
32 | /** |
||
33 | * @throws RuntimeException If no implementation is available |
||
34 | */ |
||
35 | abstract protected static function locate(string $interface): string; |
||
36 | } |
||
37 |