Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
83.33% covered (warning)
83.33%
5 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
Text
92.31% covered (success)
92.31%
12 / 13
83.33% covered (warning)
83.33%
5 / 6
9.04
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 __toString
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 raw
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
4
 strip
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 json
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isset
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace Cosray\Value;
6
7use Cosray\Field\Capability\Translatable;
8use Cosray\Field\Field;
9use Cosray\Field\Owner;
10use Override;
11
12use function Cosray\escape;
13
14/**
15 * @property-read Field&Translatable $field
16 */
17class 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}