Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
42.86% |
6 / 14 |
|
33.33% |
4 / 12 |
CRAP | |
0.00% |
0 / 1 |
| AmbiguousCall | |
42.86% |
6 / 14 |
|
33.33% |
4 / 12 |
38.87 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| withAddedName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
| __serialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __unserialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __toString | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __call | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __callStatic | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __set | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| __invoke | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| throwError | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | namespace Apie\Core\Context; |
| 3 | |
| 4 | use Apie\Core\Exceptions\AmbiguousCallException; |
| 5 | use JsonSerializable; |
| 6 | use Stringable; |
| 7 | |
| 8 | /** |
| 9 | * Magic null object class used by ApieContext when used with registerInstance in case an interface has already been registered. |
| 10 | * |
| 11 | * Any method call will throw an error. |
| 12 | * |
| 13 | * @see ApieContext::registerInstance() |
| 14 | */ |
| 15 | final class AmbiguousCall implements JsonSerializable, Stringable |
| 16 | { |
| 17 | /** @var string[] */ |
| 18 | private array $names; |
| 19 | public function __construct(private string $identifier, string... $names) |
| 20 | { |
| 21 | $this->names = $names; |
| 22 | } |
| 23 | |
| 24 | public function withAddedName(string $name): self |
| 25 | { |
| 26 | $instance = clone $this; |
| 27 | $instance->names[] = $name; |
| 28 | return $instance; |
| 29 | } |
| 30 | |
| 31 | public function __serialize(): never |
| 32 | { |
| 33 | $this->throwError(); |
| 34 | } |
| 35 | |
| 36 | /** |
| 37 | * @param mixed[] $data |
| 38 | */ |
| 39 | public function __unserialize(array $data): never |
| 40 | { |
| 41 | $this->throwError(); |
| 42 | } |
| 43 | |
| 44 | public function jsonSerialize(): never |
| 45 | { |
| 46 | $this->throwError(); |
| 47 | } |
| 48 | |
| 49 | public function __toString(): never |
| 50 | { |
| 51 | $this->throwError(); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * @param mixed[] $args |
| 56 | */ |
| 57 | public function __call(string $method, array $args): never |
| 58 | { |
| 59 | $this->throwError(); |
| 60 | } |
| 61 | |
| 62 | /** |
| 63 | * @param mixed[] $args |
| 64 | */ |
| 65 | public static function __callStatic(string $method, array $args): never |
| 66 | { |
| 67 | (new self(static::class))->throwError(); |
| 68 | } |
| 69 | |
| 70 | public function __set(mixed $name, mixed $value): never |
| 71 | { |
| 72 | $this->throwError(); |
| 73 | } |
| 74 | |
| 75 | public function __get(mixed $name): never |
| 76 | { |
| 77 | $this->throwError(); |
| 78 | } |
| 79 | |
| 80 | public function __invoke(): never |
| 81 | { |
| 82 | $this->throwError(); |
| 83 | } |
| 84 | |
| 85 | private function throwError(): never |
| 86 | { |
| 87 | throw new AmbiguousCallException($this->identifier, ...$this->names); |
| 88 | } |
| 89 | } |