| Conditions | 4 |
| Paths | 3 |
| Total Lines | 23 |
| Code Lines | 13 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 14 |
| CRAP Score | 4 |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
| 1 | <?php |
||
| 14 | 13 | public function __construct($id, $is_required = true) |
|
| 15 | { |
||
| 16 | 13 | static $empty_values = [null, false, 0, '0', '']; |
|
| 17 | |||
| 18 | 13 | if (in_array($id, $empty_values, true) && !$is_required) { |
|
| 19 | 3 | $id = null; |
|
| 20 | 3 | } else { |
|
| 21 | $options = [ |
||
| 22 | 10 | 'flags' => \FILTER_REQUIRE_SCALAR, |
|
| 23 | 'options' => [ |
||
| 24 | 10 | 'min_range' => 1, |
|
| 25 | 10 | ], |
|
| 26 | 10 | ]; |
|
| 27 | |||
| 28 | 10 | if (filter_var($id, \FILTER_VALIDATE_INT, $options) === false) { |
|
| 29 | 7 | throw new InvalidArgumentException('Value must be a valid identifier'); |
|
| 30 | } |
||
| 31 | |||
| 32 | 3 | $id = (int) $id; |
|
| 33 | } |
||
| 34 | |||
| 35 | 6 | $this->id = $id; |
|
| 36 | 6 | } |
|
| 37 | |||
| 43 |