| Conditions | 4 |
| Paths | 4 |
| Total Lines | 20 |
| Code Lines | 10 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 4 |
| 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 | $options = [ |
||
| 20 | 17 | 'flags' => \FILTER_NULL_ON_FAILURE | \FILTER_REQUIRE_SCALAR, |
|
| 21 | 17 | ]; |
|
| 22 | |||
| 23 | 17 | $value = filter_var($value, \FILTER_VALIDATE_BOOLEAN, $options); |
|
| 24 | |||
| 25 | 17 | if ($value === null) { |
|
| 26 | 4 | throw new InvalidArgumentException('Value must be boolean flag'); |
|
| 27 | } |
||
| 28 | |||
| 29 | 13 | $this->value = $value; |
|
| 30 | 13 | } |
|
| 31 | |||
| 37 |