| Conditions | 7 |
| Paths | 20 |
| Total Lines | 26 |
| Code Lines | 20 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 7 | protected function validateCastValue($val) |
||
| 8 | { |
||
| 9 | if (isset($this->descriptor()->trueValues)) { |
||
| 10 | $trueValues = $this->descriptor()->trueValues; |
||
| 11 | } else { |
||
| 12 | $trueValues = ['true', 'True', 'TRUE', '1']; |
||
| 13 | } |
||
| 14 | if (isset($this->descriptor()->falseValues)) { |
||
| 15 | $falseValues = $this->descriptor()->falseValues; |
||
| 16 | } else { |
||
| 17 | $falseValues = ['false', 'False', 'FALSE', '0']; |
||
| 18 | } |
||
| 19 | if (is_bool($val)) { |
||
| 20 | return $val; |
||
| 21 | } elseif (is_string($val)) { |
||
| 22 | if (in_array($val, $trueValues)) { |
||
| 23 | return true; |
||
| 24 | } elseif (in_array($val, $falseValues)) { |
||
| 25 | return false; |
||
| 26 | } else { |
||
| 27 | throw $this->getValidationException('invalid bool value', $val); |
||
| 28 | } |
||
| 29 | } else { |
||
| 30 | throw $this->getValidationException('value must be a bool or string', $val); |
||
| 31 | } |
||
| 32 | } |
||
| 33 | |||
| 39 |