Total Complexity | 7 |
Total Lines | 87 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | abstract class AbstractValueType implements ValueTypeInterface |
||
13 | { |
||
14 | /** |
||
15 | * Set the value for this type. |
||
16 | * |
||
17 | * @param string $value |
||
18 | */ |
||
19 | final protected function __construct( |
||
20 | protected string $value, |
||
21 | ) { |
||
22 | $this->validateValue($value); |
||
23 | } |
||
24 | |||
25 | |||
26 | /** |
||
27 | * Get the value. |
||
28 | * |
||
29 | * @return string |
||
30 | */ |
||
31 | public function getValue(): string |
||
34 | } |
||
35 | |||
36 | |||
37 | /** |
||
38 | * Get the raw unsanitized value. |
||
39 | * |
||
40 | * @return string |
||
41 | */ |
||
42 | public function getRawValue(): string |
||
43 | { |
||
44 | return $this->value; |
||
45 | } |
||
46 | |||
47 | |||
48 | /** |
||
49 | * Sanitize the value. |
||
50 | * |
||
51 | * @param string $value The value |
||
52 | * @throws \Exception on failure |
||
53 | * @return string |
||
54 | */ |
||
55 | protected function sanitizeValue(string $value): string |
||
56 | { |
||
57 | /** |
||
58 | * Perform no sanitation by default. |
||
59 | * Override this method on the implementing class to perform content sanitation. |
||
60 | */ |
||
61 | return $value; |
||
62 | } |
||
63 | |||
64 | |||
65 | /** |
||
66 | * Validate the value. |
||
67 | * |
||
68 | * @param string $value The value |
||
69 | * @throws \Exception on failure |
||
70 | * @return void |
||
71 | */ |
||
72 | protected function validateValue(/** @scrutinizer ignore-unused */ string $value): void |
||
74 | /** |
||
75 | * Perform no validation by default. |
||
76 | * Override this method on the implementing class to perform validation. |
||
77 | */ |
||
78 | } |
||
79 | |||
80 | |||
81 | /** |
||
82 | * @param string $value |
||
83 | * @return static |
||
84 | */ |
||
85 | public static function fromString(string $value): static |
||
86 | { |
||
87 | return new static($value); |
||
88 | } |
||
89 | |||
90 | |||
91 | /** |
||
92 | * Output the value as a string |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | public function __toString(): string |
||
99 | } |
||
100 | } |
||
101 |