Conditions | 4 |
Paths | 4 |
Total Lines | 21 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
24 | public function validate($value) |
||
25 | { |
||
26 | $initialValue = $this->copyValue($value); |
||
27 | |||
28 | foreach ($this->types as $type) { |
||
29 | $currentValue = $this->copyValue($initialValue); |
||
30 | |||
31 | try { |
||
32 | $currentValue = $type->validate($currentValue); |
||
33 | } catch (TypeError $typeError) { |
||
34 | continue; |
||
35 | } |
||
36 | |||
37 | if (! $this->sameType($initialValue, $currentValue, $type)) { |
||
38 | continue; |
||
39 | } |
||
40 | |||
41 | return $initialValue; |
||
42 | } |
||
43 | |||
44 | throw WrongType::withMessage("Type must be either one of: {$this->getAvailableTypesString()}"); |
||
45 | } |
||
85 |