Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
15 / 15 |
|
100.00% |
17 / 17 |
|
71.43% |
10 / 14 |
|
100.00% |
6 / 6 |
CRAP | |
100.00% |
1 / 1 |
| Args | |
100.00% |
15 / 15 |
|
100.00% |
17 / 17 |
|
71.43% |
10 / 14 |
|
100.00% |
6 / 6 |
13.82 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| get | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getNamed | |
100.00% |
3 / 3 |
|
100.00% |
5 / 5 |
|
50.00% |
2 / 4 |
|
100.00% |
1 / 1 |
4.12 | |||
| count | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| prepare | |
100.00% |
8 / 8 |
|
100.00% |
8 / 8 |
|
66.67% |
4 / 6 |
|
100.00% |
1 / 1 |
4.59 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celemas\Quma; |
| 6 | |
| 7 | /** |
| 8 | * @psalm-type ArgsArray = list<mixed>|array<non-empty-string, mixed> |
| 9 | */ |
| 10 | final class Args |
| 11 | { |
| 12 | private ArgType $type; |
| 13 | private int $count; |
| 14 | |
| 15 | /** @psalm-var ArgsArray */ |
| 16 | private readonly array $args; |
| 17 | |
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->args = $this->prepare($args); |
| 21 | } |
| 22 | |
| 23 | /** @psalm-return ArgsArray */ |
| 24 | public function get(): array |
| 25 | { |
| 26 | return $this->args; |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * @return array<array-key, mixed> |
| 31 | */ |
| 32 | public function getNamed(): array |
| 33 | { |
| 34 | if ($this->type !== ArgType::Named || !Util::isAssoc($this->args)) { |
| 35 | return []; |
| 36 | } |
| 37 | |
| 38 | return $this->args; |
| 39 | } |
| 40 | |
| 41 | public function count(): int |
| 42 | { |
| 43 | return $this->count; |
| 44 | } |
| 45 | |
| 46 | public function type(): ArgType |
| 47 | { |
| 48 | return $this->type; |
| 49 | } |
| 50 | |
| 51 | private function prepare(array $args): array |
| 52 | { |
| 53 | $this->count = count($args); |
| 54 | |
| 55 | if ($this->count === 1 && is_array($args[0])) { |
| 56 | if (Util::isAssoc($args[0])) { |
| 57 | $this->type = ArgType::Named; |
| 58 | } else { |
| 59 | $this->type = ArgType::Positional; |
| 60 | } |
| 61 | |
| 62 | return $args[0]; |
| 63 | } |
| 64 | |
| 65 | $this->type = ArgType::Positional; |
| 66 | |
| 67 | return $args; |
| 68 | } |
| 69 | } |
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.
| 18 | public function __construct(array $args) |
| 19 | { |
| 20 | $this->args = $this->prepare($args); |
| 21 | } |
| 43 | return $this->count; |
| 44 | } |
| 26 | return $this->args; |
| 27 | } |
| 34 | if ($this->type !== ArgType::Named || !Util::isAssoc($this->args)) { |
| 34 | if ($this->type !== ArgType::Named || !Util::isAssoc($this->args)) { |
| 34 | if ($this->type !== ArgType::Named || !Util::isAssoc($this->args)) { |
| 35 | return []; |
| 38 | return $this->args; |
| 39 | } |
| 51 | private function prepare(array $args): array |
| 52 | { |
| 53 | $this->count = count($args); |
| 54 | |
| 55 | if ($this->count === 1 && is_array($args[0])) { |
| 55 | if ($this->count === 1 && is_array($args[0])) { |
| 55 | if ($this->count === 1 && is_array($args[0])) { |
| 56 | if (Util::isAssoc($args[0])) { |
| 56 | if (Util::isAssoc($args[0])) { |
| 57 | $this->type = ArgType::Named; |
| 59 | $this->type = ArgType::Positional; |
| 60 | } |
| 61 | |
| 62 | return $args[0]; |
| 62 | return $args[0]; |
| 65 | $this->type = ArgType::Positional; |
| 66 | |
| 67 | return $args; |
| 68 | } |
| 48 | return $this->type; |
| 49 | } |