Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
90.91% |
10 / 11 |
|
80.00% |
4 / 5 |
CRAP | |
0.00% |
0 / 1 |
| Number | |
90.91% |
10 / 11 |
|
80.00% |
4 / 5 |
8.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
2 | |||
| __toString | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
| json | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| unwrap | |
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 | |
| 10 | class Number extends Value |
| 11 | { |
| 12 | public readonly ?int $value; |
| 13 | |
| 14 | public function __construct(Owner $owner, Field $field, ValueContext $context) |
| 15 | { |
| 16 | parent::__construct($owner, $field, $context); |
| 17 | |
| 18 | $value = $this->value(); |
| 19 | |
| 20 | if (is_numeric($value)) { |
| 21 | $this->value = (int) $value; |
| 22 | } else { |
| 23 | $this->value = null; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | public function __toString(): string |
| 28 | { |
| 29 | if ($this->value === null) { |
| 30 | return ''; |
| 31 | } |
| 32 | |
| 33 | return (string) $this->value; |
| 34 | } |
| 35 | |
| 36 | public function json(): ?int |
| 37 | { |
| 38 | return $this->unwrap(); |
| 39 | } |
| 40 | |
| 41 | public function unwrap(): ?int |
| 42 | { |
| 43 | return $this->value; |
| 44 | } |
| 45 | |
| 46 | public function isset(): bool |
| 47 | { |
| 48 | return isset($this->value) ? true : false; |
| 49 | } |
| 50 | } |