| Total Complexity | 7 |
| Total Lines | 39 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 29 | final class Reference implements ReferenceInterface |
||
| 30 | { |
||
| 31 | private string $id; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * @throws InvalidConfigException |
||
| 35 | */ |
||
| 36 | 12 | private function __construct(mixed $id, private bool $optional) |
|
| 37 | { |
||
| 38 | 12 | if (!is_string($id)) { |
|
| 39 | 1 | throw new InvalidConfigException('Reference ID must be string.'); |
|
| 40 | } |
||
| 41 | |||
| 42 | 11 | $this->id = $id; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @throws InvalidConfigException If ID is not string. |
||
| 47 | */ |
||
| 48 | 11 | public static function to(mixed $id): self |
|
| 49 | { |
||
| 50 | 11 | return new self($id, false); |
|
| 51 | } |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Optional reference returns `null` when there is no corresponding definition in container. |
||
| 55 | * |
||
| 56 | * @param mixed $id ID of the service or object to point to. |
||
| 57 | * |
||
| 58 | * @throws InvalidConfigException If ID is not string. |
||
| 59 | */ |
||
| 60 | 1 | public static function optional(mixed $id): self |
|
| 63 | } |
||
| 64 | |||
| 65 | 9 | public function resolve(ContainerInterface $container): mixed |
|
| 70 |