Code Coverage |
||||||||||||||||
Lines |
Branches |
Paths |
Functions and Methods |
Classes and Traits |
||||||||||||
| Total | |
100.00% |
7 / 7 |
|
100.00% |
8 / 8 |
|
60.00% |
3 / 5 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| DefaultCoercers | |
100.00% |
7 / 7 |
|
100.00% |
8 / 8 |
|
60.00% |
3 / 5 |
|
100.00% |
2 / 2 |
5.02 | |
100.00% |
1 / 1 |
| get | |
100.00% |
2 / 2 |
|
100.00% |
4 / 4 |
|
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
2 | |||
| all | |
100.00% |
5 / 5 |
|
100.00% |
4 / 4 |
|
33.33% |
1 / 3 |
|
100.00% |
1 / 1 |
3.19 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Celema\Sire; |
| 6 | |
| 7 | use Override; |
| 8 | |
| 9 | final class DefaultCoercers implements Contract\CoercerRegistry |
| 10 | { |
| 11 | private const array COERCERS = [ |
| 12 | 'string' => Coercer\Str::class, |
| 13 | 'bool' => Coercer\Boolean::class, |
| 14 | 'list' => Coercer\ListArray::class, |
| 15 | 'float' => Coercer\FloatingPoint::class, |
| 16 | 'int' => Coercer\Integer::class, |
| 17 | 'number' => Coercer\Number::class, |
| 18 | ]; |
| 19 | |
| 20 | /** @var array<string, Contract\Coercer> */ |
| 21 | private array $loaded = []; |
| 22 | |
| 23 | #[Override] |
| 24 | public function get(string $name): ?Contract\Coercer |
| 25 | { |
| 26 | $class = self::COERCERS[$name] ?? null; |
| 27 | |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 29 | } |
| 30 | |
| 31 | #[Override] |
| 32 | public function all(): array |
| 33 | { |
| 34 | $coercers = []; |
| 35 | |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 37 | $this->loaded[$name] ??= new $class(); |
| 38 | $coercers[$name] = $this->loaded[$name]; |
| 39 | } |
| 40 | |
| 41 | return $coercers; |
| 42 | } |
| 43 | } |
Below are the source code lines that represent each code path as identified by Xdebug. Please note a path is not
necessarily coterminous with a line, a line may contain multiple paths and therefore show up more than once.
Please also be aware that some paths may include implicit rather than explicit branches, e.g. an if statement
always has an else as part of its logical flow even if you didn't write one.
| 34 | $coercers = []; |
| 35 | |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 37 | $this->loaded[$name] ??= new $class(); |
| 38 | $coercers[$name] = $this->loaded[$name]; |
| 39 | } |
| 40 | |
| 41 | return $coercers; |
| 42 | } |
| 34 | $coercers = []; |
| 35 | |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 37 | $this->loaded[$name] ??= new $class(); |
| 38 | $coercers[$name] = $this->loaded[$name]; |
| 39 | } |
| 40 | |
| 41 | return $coercers; |
| 42 | } |
| 34 | $coercers = []; |
| 35 | |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 36 | foreach (self::COERCERS as $name => $class) { |
| 37 | $this->loaded[$name] ??= new $class(); |
| 38 | $coercers[$name] = $this->loaded[$name]; |
| 39 | } |
| 40 | |
| 41 | return $coercers; |
| 42 | } |
| 24 | public function get(string $name): ?Contract\Coercer |
| 25 | { |
| 26 | $class = self::COERCERS[$name] ?? null; |
| 27 | |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 29 | } |
| 24 | public function get(string $name): ?Contract\Coercer |
| 25 | { |
| 26 | $class = self::COERCERS[$name] ?? null; |
| 27 | |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 28 | return $class === null ? null : ($this->loaded[$name] ??= new $class()); |
| 29 | } |