Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
83.33% |
5 / 6 |
CRAP | |
0.00% |
0 / 1 |
| Text | |
92.31% |
12 / 13 |
|
83.33% |
5 / 6 |
9.04 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| __toString | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| raw | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
4 | |||
| strip | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| json | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| isset | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Cosray\Value; |
| 6 | |
| 7 | use Cosray\Field\Capability\Translatable; |
| 8 | use Cosray\Field\Field; |
| 9 | use Cosray\Field\Owner; |
| 10 | use Override; |
| 11 | |
| 12 | use function Cosray\escape; |
| 13 | |
| 14 | /** |
| 15 | * @property-read Field&Translatable $field |
| 16 | */ |
| 17 | class Text extends Value |
| 18 | { |
| 19 | protected string $value; |
| 20 | |
| 21 | public function __construct( |
| 22 | Owner $owner, |
| 23 | Field&Translatable $field, |
| 24 | ValueContext $context, |
| 25 | ) { |
| 26 | parent::__construct($owner, $field, $context); |
| 27 | } |
| 28 | |
| 29 | #[Override] |
| 30 | public function __toString(): string |
| 31 | { |
| 32 | return escape($this->raw()); |
| 33 | } |
| 34 | |
| 35 | #[Override] |
| 36 | public function raw(): string |
| 37 | { |
| 38 | if (isset($this->value)) { |
| 39 | return $this->value; |
| 40 | } |
| 41 | |
| 42 | $value = $this->value(); |
| 43 | |
| 44 | if (is_string($value) || is_numeric($value)) { |
| 45 | $this->value = (string) $value; |
| 46 | |
| 47 | return $this->value; |
| 48 | } |
| 49 | |
| 50 | $this->value = ''; |
| 51 | |
| 52 | return ''; |
| 53 | } |
| 54 | |
| 55 | /** @param list<string>|string|null $allowed */ |
| 56 | public function strip(array|string|null $allowed = null): string |
| 57 | { |
| 58 | return strip_tags((string) $this->raw(), $allowed); |
| 59 | } |
| 60 | |
| 61 | #[Override] |
| 62 | public function json(): mixed |
| 63 | { |
| 64 | return $this->raw(); |
| 65 | } |
| 66 | |
| 67 | #[Override] |
| 68 | public function isset(): bool |
| 69 | { |
| 70 | return (bool) $this->raw(); |
| 71 | } |
| 72 | } |