Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| IntField | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |
0.00% |
0 / 1 |
| parse | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
4.03 | |||
| 1 | <?php declare(strict_types=1); |
| 2 | |
| 3 | namespace Computator\FrameworkUtils\InputParser\Field; |
| 4 | |
| 5 | use function is_int, is_numeric; |
| 6 | |
| 7 | class IntField extends Base { |
| 8 | public function parse(mixed $value): int { |
| 9 | if (is_int($value)) |
| 10 | return $value; |
| 11 | if (!is_numeric($value)) |
| 12 | throw new \ValueError("value is not a numeric string"); |
| 13 | $i = $value + 0; // cast to int or float |
| 14 | if (!is_int($i)) |
| 15 | throw new \ValueError("parsed value does not result in an integer"); |
| 16 | return $i; |
| 17 | } |
| 18 | } |