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