Total Complexity | 7 |
Total Lines | 29 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
19 | trait Resolvable |
||
20 | { |
||
21 | protected static $resolved = []; |
||
22 | |||
23 | 672 | protected static function resolveInstance($instance, ...$parameters) |
|
24 | { |
||
25 | 672 | $class = is_object($instance) ? get_class($instance) : $instance; |
|
26 | |||
27 | 672 | if (isset(self::$resolved[$class])) { |
|
28 | 521 | return self::$resolved[$class]; |
|
29 | } |
||
30 | |||
31 | 671 | return self::$resolved[$class] = is_object($instance) ? $instance : new $instance(...$parameters); |
|
32 | } |
||
33 | |||
34 | 1 | protected static function resolveCallback(string $value, callable $callback) |
|
35 | { |
||
36 | 1 | $class = static::getSameClass(); |
|
37 | |||
38 | 1 | if (isset(static::$resolved[$class][$value])) { |
|
39 | 1 | return static::$resolved[$class][$value]; |
|
40 | } |
||
41 | |||
42 | 1 | return static::$resolved[$class][$value] = $callback($value); |
|
43 | } |
||
44 | |||
45 | 2 | protected static function getSameClass(): string |
|
48 | } |
||
49 | } |
||
50 |