Conditions | 5 |
Paths | 5 |
Total Lines | 24 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 10 |
CRAP Score | 5.0187 |
Changes | 0 |
1 | <?php |
||
54 | 6 | private function fetchOptions(iterable $rules, bool $dumpRuleName): array |
|
55 | { |
||
56 | 6 | $result = []; |
|
57 | 6 | foreach ($rules as $attribute => $rule) { |
|
58 | 6 | if (is_array($rule)) { |
|
59 | 2 | $result[$attribute] = $this->fetchOptions($rule, $dumpRuleName); |
|
60 | 6 | } elseif ($rule instanceof RuleInterface) { |
|
61 | 6 | if ($dumpRuleName) { |
|
62 | 2 | $result[$attribute] = array_merge([$rule->getName()], $rule->getOptions()); |
|
63 | } else { |
||
64 | 6 | $result[$attribute] = $rule->getOptions(); |
|
65 | } |
||
66 | } else { |
||
67 | // or ? |
||
68 | // $result[$attribute] = [get_class($rule)]; |
||
69 | |||
70 | throw new InvalidArgumentException(sprintf( |
||
71 | 'Rules should be an array of rules that implements %s.', |
||
72 | RuleInterface::class, |
||
73 | )); |
||
74 | } |
||
75 | } |
||
76 | |||
77 | 6 | return $result; |
|
78 | } |
||
80 |