Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| Utils | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
5 | |
100.00% |
1 / 1 |
| transform_context | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
5 | |||
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Computator\FrameworkUtils\PHPTemplate; |
| 4 | |
| 5 | use ValueError; |
| 6 | |
| 7 | use function array_is_list, is_array, is_int; |
| 8 | |
| 9 | class Utils { |
| 10 | /** @return array<string,mixed> */ |
| 11 | public static function transform_context(array $context): array { |
| 12 | $out = []; |
| 13 | foreach ($context as $k => $v) { |
| 14 | if (is_int($k)) { |
| 15 | if (!is_array($v)) |
| 16 | throw new ValueError("non-array values require a non-numeric key"); |
| 17 | if (array_is_list($v)) |
| 18 | throw new ValueError("list array values require a non-numeric key"); |
| 19 | $out = [...$out, ...$v]; |
| 20 | } |
| 21 | else |
| 22 | $out[$k] = $v; |
| 23 | } |
| 24 | return $out; |
| 25 | } |
| 26 | } |