| Total Complexity | 9 |
| Total Lines | 56 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 8 | abstract class Story |
||
| 9 | { |
||
| 10 | /** @var array<string, Proxy> */ |
||
| 11 | private array $objects = []; |
||
| 12 | |||
| 13 | 38 | private function __construct() |
|
| 14 | { |
||
| 15 | 38 | } |
|
| 16 | |||
| 17 | 2 | final public function __call(string $method, array $arguments) |
|
| 18 | { |
||
| 19 | 2 | return $this->get($method); |
|
| 20 | } |
||
| 21 | |||
| 22 | 4 | public static function __callStatic($name, $arguments) |
|
| 23 | { |
||
| 24 | 4 | return static::load()->get($name); |
|
| 25 | } |
||
| 26 | |||
| 27 | 38 | final public static function load(): self |
|
| 39 | } |
||
| 40 | |||
| 41 | 38 | final public function add(string $name, object $object): self |
|
| 42 | { |
||
| 43 | // ensure factories are persisted |
||
| 44 | 38 | if ($object instanceof Factory) { |
|
| 45 | 2 | $object = $object->persist(); |
|
| 46 | } |
||
| 47 | |||
| 48 | // ensure all objects are wrapped in a auto-refreshing proxy |
||
| 49 | 38 | $this->objects[$name] = PersistenceManager::proxy($object)->withAutoRefresh(); |
|
| 50 | |||
| 51 | 38 | return $this; |
|
| 52 | } |
||
| 53 | |||
| 54 | 8 | final public function get(string $name): Proxy |
|
| 61 | } |
||
| 62 | |||
| 63 | abstract protected function build(): void; |
||
| 64 | } |
||
| 65 |