Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
CRAP | |
100.00% |
1 / 1 |
| Number | |
100.00% |
11 / 11 |
|
100.00% |
5 / 5 |
8 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| __toString | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| json | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| raw | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Value; |
| 6 | |
| 7 | use Cosray\Field\Field; |
| 8 | use Cosray\Field\Owner; |
| 9 | use Override; |
| 10 | |
| 11 | class Number extends Value |
| 12 | { |
| 13 | public readonly ?int $value; |
| 14 | |
| 15 | public function __construct(Owner $owner, Field $field, ValueContext $context) |
| 16 | { |
| 17 | parent::__construct($owner, $field, $context); |
| 18 | |
| 19 | $value = $this->value(); |
| 20 | |
| 21 | if (is_numeric($value)) { |
| 22 | $this->value = (int) $value; |
| 23 | } else { |
| 24 | $this->value = null; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | #[Override] |
| 29 | public function __toString(): string |
| 30 | { |
| 31 | if ($this->value === null) { |
| 32 | return ''; |
| 33 | } |
| 34 | |
| 35 | return (string) $this->value; |
| 36 | } |
| 37 | |
| 38 | #[Override] |
| 39 | public function json(): ?int |
| 40 | { |
| 41 | return $this->raw(); |
| 42 | } |
| 43 | |
| 44 | #[Override] |
| 45 | public function raw(): ?int |
| 46 | { |
| 47 | return $this->value; |
| 48 | } |
| 49 | |
| 50 | #[Override] |
| 51 | public function isset(): bool |
| 52 | { |
| 53 | return isset($this->value) ? true : false; |
| 54 | } |
| 55 | } |