| Conditions | 5 |
| Paths | 6 |
| Total Lines | 24 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 5 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 11 | 17 | public function __construct($value, $default = null) |
|
| 12 | { |
||
| 13 | 17 | static $empty_values = [null, '']; |
|
| 14 | |||
| 15 | 17 | if (is_bool($default) && in_array($value, $empty_values, true)) { |
|
| 16 | 1 | $value = $default; |
|
| 17 | 1 | } |
|
| 18 | |||
| 19 | 17 | if (!is_scalar($value)) { |
|
| 20 | 2 | throw new InvalidArgumentException('Value must a possible boolean'); |
|
| 21 | } |
||
| 22 | |||
| 23 | $options = [ |
||
| 24 | 15 | 'flags' => \FILTER_NULL_ON_FAILURE, |
|
| 25 | 15 | ]; |
|
| 26 | |||
| 27 | 15 | $value = filter_var($value, \FILTER_VALIDATE_BOOLEAN, $options); |
|
| 28 | |||
| 29 | 15 | if ($value === null) { |
|
| 30 | 3 | throw new InvalidArgumentException('Value must be boolean'); |
|
| 31 | } |
||
| 32 | |||
| 33 | 12 | $this->value = $value; |
|
| 34 | 12 | } |
|
| 35 | |||
| 41 |