Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
36 / 36 |
|
100.00% |
28 / 28 |
|
90.91% |
20 / 22 |
|
100.00% |
15 / 15 |
CRAP | |
100.00% |
1 / 1 |
| Entry | |
100.00% |
36 / 36 |
|
100.00% |
28 / 28 |
|
90.91% |
20 / 22 |
|
100.00% |
15 / 15 |
21.33 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| lifetime | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shared | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| scoped | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| transient | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getLifetime | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| value | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| shouldReturnValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| args | |
100.00% |
18 / 18 |
|
100.00% |
14 / 14 |
|
75.00% |
6 / 8 |
|
100.00% |
1 / 1 |
7.77 | |||
| getArgs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| constructor | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getConstructor | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| call | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getCalls | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| definition | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Container; |
| 6 | |
| 7 | use Celemas\Container\Exception\ContainerException; |
| 8 | use Celemas\Wire\Call; |
| 9 | use Closure; |
| 10 | |
| 11 | /** @psalm-api */ |
| 12 | class Entry |
| 13 | { |
| 14 | /** @var array<array-key, mixed>|Closure(mixed...): array<array-key, mixed>|null */ |
| 15 | protected array|Closure|null $args = null; |
| 16 | |
| 17 | protected ?string $constructor = null; |
| 18 | protected bool $value = false; |
| 19 | protected Lifetime $lifetime = Lifetime::Shared; |
| 20 | |
| 21 | /** @var list<Call> */ |
| 22 | protected array $calls = []; |
| 23 | |
| 24 | /** |
| 25 | * @param non-empty-string $id |
| 26 | */ |
| 27 | public function __construct( |
| 28 | public readonly string $id, |
| 29 | protected mixed $definition, |
| 30 | ) {} |
| 31 | |
| 32 | public function lifetime(Lifetime $lifetime): static |
| 33 | { |
| 34 | $this->lifetime = $lifetime; |
| 35 | |
| 36 | return $this; |
| 37 | } |
| 38 | |
| 39 | public function shared(): static |
| 40 | { |
| 41 | return $this->lifetime(Lifetime::Shared); |
| 42 | } |
| 43 | |
| 44 | public function scoped(): static |
| 45 | { |
| 46 | return $this->lifetime(Lifetime::Scoped); |
| 47 | } |
| 48 | |
| 49 | public function transient(): static |
| 50 | { |
| 51 | return $this->lifetime(Lifetime::Transient); |
| 52 | } |
| 53 | |
| 54 | public function getLifetime(): Lifetime |
| 55 | { |
| 56 | return $this->lifetime; |
| 57 | } |
| 58 | |
| 59 | public function value(bool $value = true): static |
| 60 | { |
| 61 | $this->value = $value; |
| 62 | |
| 63 | return $this; |
| 64 | } |
| 65 | |
| 66 | public function shouldReturnValue(): bool |
| 67 | { |
| 68 | return $this->value; |
| 69 | } |
| 70 | |
| 71 | public function args(mixed ...$args): static |
| 72 | { |
| 73 | $numArgs = count($args); |
| 74 | |
| 75 | if ($numArgs === 1) { |
| 76 | if (is_string(array_key_first($args))) { |
| 77 | $this->args = $args; |
| 78 | } elseif (is_array($args[0]) || $args[0] instanceof Closure) { |
| 79 | /** @var array<array-key, mixed>|Closure(mixed...): array<array-key, mixed> */ |
| 80 | $this->args = $args[0]; |
| 81 | } else { |
| 82 | throw new ContainerException( |
| 83 | 'Container entry arguments can be passed as a single associative array, ' |
| 84 | . 'as named arguments, or as a Closure', |
| 85 | ); |
| 86 | } |
| 87 | } elseif ($numArgs > 1) { |
| 88 | if (!is_string(array_key_first($args))) { |
| 89 | throw new ContainerException( |
| 90 | 'Container entry arguments can be passed as a single associative array, ' |
| 91 | . 'as named arguments, or as a Closure', |
| 92 | ); |
| 93 | } |
| 94 | |
| 95 | $this->args = $args; |
| 96 | } |
| 97 | |
| 98 | return $this; |
| 99 | } |
| 100 | |
| 101 | /** @return array<array-key, mixed>|Closure(mixed...): array<array-key, mixed>|null */ |
| 102 | public function getArgs(): array|Closure|null |
| 103 | { |
| 104 | return $this->args; |
| 105 | } |
| 106 | |
| 107 | public function constructor(string $methodName): static |
| 108 | { |
| 109 | $this->constructor = $methodName; |
| 110 | |
| 111 | return $this; |
| 112 | } |
| 113 | |
| 114 | public function getConstructor(): ?string |
| 115 | { |
| 116 | return $this->constructor; |
| 117 | } |
| 118 | |
| 119 | public function call(string $method, mixed ...$args): static |
| 120 | { |
| 121 | $this->calls[] = new Call($method, ...$args); |
| 122 | |
| 123 | return $this; |
| 124 | } |
| 125 | |
| 126 | /** @return list<Call> */ |
| 127 | public function getCalls(): array |
| 128 | { |
| 129 | return $this->calls; |
| 130 | } |
| 131 | |
| 132 | public function definition(): mixed |
| 133 | { |
| 134 | return $this->definition; |
| 135 | } |
| 136 | } |
Below are the source code lines that represent each code branch as identified by Xdebug. Please note a branch is not
necessarily coterminous with a line, a line may contain multiple branches and therefore show up more than once.
Please also be aware that some branches may be implicit rather than explicit, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 28 | public readonly string $id, |
| 29 | protected mixed $definition, |
| 30 | ) {} |
| 71 | public function args(mixed ...$args): static |
| 72 | { |
| 73 | $numArgs = count($args); |
| 74 | |
| 75 | if ($numArgs === 1) { |
| 76 | if (is_string(array_key_first($args))) { |
| 76 | if (is_string(array_key_first($args))) { |
| 77 | $this->args = $args; |
| 78 | } elseif (is_array($args[0]) || $args[0] instanceof Closure) { |
| 78 | } elseif (is_array($args[0]) || $args[0] instanceof Closure) { |
| 78 | } elseif (is_array($args[0]) || $args[0] instanceof Closure) { |
| 78 | } elseif (is_array($args[0]) || $args[0] instanceof Closure) { |
| 79 | /** @var array<array-key, mixed>|Closure(mixed...): array<array-key, mixed> */ |
| 80 | $this->args = $args[0]; |
| 82 | throw new ContainerException( |
| 83 | 'Container entry arguments can be passed as a single associative array, ' |
| 84 | . 'as named arguments, or as a Closure', |
| 75 | if ($numArgs === 1) { |
| 87 | } elseif ($numArgs > 1) { |
| 88 | if (!is_string(array_key_first($args))) { |
| 89 | throw new ContainerException( |
| 90 | 'Container entry arguments can be passed as a single associative array, ' |
| 91 | . 'as named arguments, or as a Closure', |
| 95 | $this->args = $args; |
| 96 | } |
| 97 | |
| 98 | return $this; |
| 98 | return $this; |
| 99 | } |
| 119 | public function call(string $method, mixed ...$args): static |
| 120 | { |
| 121 | $this->calls[] = new Call($method, ...$args); |
| 122 | |
| 123 | return $this; |
| 124 | } |
| 107 | public function constructor(string $methodName): static |
| 108 | { |
| 109 | $this->constructor = $methodName; |
| 110 | |
| 111 | return $this; |
| 112 | } |
| 134 | return $this->definition; |
| 135 | } |
| 104 | return $this->args; |
| 105 | } |
| 129 | return $this->calls; |
| 130 | } |
| 116 | return $this->constructor; |
| 117 | } |
| 56 | return $this->lifetime; |
| 57 | } |
| 32 | public function lifetime(Lifetime $lifetime): static |
| 33 | { |
| 34 | $this->lifetime = $lifetime; |
| 35 | |
| 36 | return $this; |
| 37 | } |
| 46 | return $this->lifetime(Lifetime::Scoped); |
| 47 | } |
| 41 | return $this->lifetime(Lifetime::Shared); |
| 42 | } |
| 68 | return $this->value; |
| 69 | } |
| 51 | return $this->lifetime(Lifetime::Transient); |
| 52 | } |
| 59 | public function value(bool $value = true): static |
| 60 | { |
| 61 | $this->value = $value; |
| 62 | |
| 63 | return $this; |
| 64 | } |