Total Complexity | 5 |
Total Lines | 46 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
12 | abstract class BaseString extends Element implements StringType |
||
13 | { |
||
14 | /** |
||
15 | * String value. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $_string; |
||
20 | |||
21 | /** |
||
22 | * Constructor. |
||
23 | * |
||
24 | * @throws \InvalidArgumentException |
||
25 | */ |
||
26 | 137 | public function __construct(string $string) |
|
27 | { |
||
28 | 137 | if (!$this->_validateString($string)) { |
|
29 | 9 | throw new \InvalidArgumentException( |
|
30 | 9 | sprintf('Not a valid %s string.', self::tagToName($this->_typeTag))); |
|
31 | } |
||
32 | 128 | $this->_string = $string; |
|
33 | 128 | } |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 1 | public function __toString(): string |
|
39 | { |
||
40 | 1 | return $this->string(); |
|
41 | } |
||
42 | |||
43 | /** |
||
44 | * Get the string value. |
||
45 | */ |
||
46 | 50 | public function string(): string |
|
49 | } |
||
50 | |||
51 | /** |
||
52 | * Check whether string is valid for the concrete type. |
||
53 | */ |
||
54 | 69 | protected function _validateString(string $string): bool |
|
58 | } |
||
59 | } |
||
60 |