Conditions | 7 |
Paths | 7 |
Total Lines | 29 |
Code Lines | 17 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
13 | public function __construct(array $values) { |
||
14 | |||
15 | $parameters = []; |
||
16 | |||
17 | foreach ($values as $k => $v) { |
||
18 | if (is_string($v)) { |
||
19 | $parameters[$k] = ['type' => $v]; |
||
20 | } |
||
21 | elseif ([] === $v) { |
||
22 | // @todo Is this allowed? |
||
23 | $parameters[$k] = []; |
||
24 | } |
||
25 | elseif (is_array($v)) { |
||
26 | if ('type' !== array_keys($v)) { |
||
27 | throw new \RuntimeException("Parameter array must have only one key, 'type'."); |
||
28 | } |
||
29 | $type = $v['type']; |
||
30 | if (!is_string($type)) { |
||
31 | throw new \RuntimeException("Parameter type must be a string."); |
||
32 | } |
||
33 | $parameters[$k] = ['type' => $type]; |
||
34 | } |
||
35 | else { |
||
36 | throw new \RuntimeException("Parameter must be an array or a string."); |
||
37 | } |
||
38 | } |
||
39 | |||
40 | parent::__construct(['options' => $parameters]); |
||
41 | } |
||
42 | |||
44 |