| Total Complexity | 5 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 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 | * @param string $string |
||
| 25 | * |
||
| 26 | * @throws \InvalidArgumentException |
||
| 27 | */ |
||
| 28 | 136 | public function __construct(string $string) |
|
| 29 | { |
||
| 30 | 136 | if (!$this->_validateString($string)) { |
|
| 31 | 8 | throw new \InvalidArgumentException( |
|
| 32 | 8 | sprintf('Not a valid %s string.', |
|
| 33 | 8 | self::tagToName($this->_typeTag))); |
|
| 34 | } |
||
| 35 | 128 | $this->_string = $string; |
|
| 36 | 128 | } |
|
| 37 | |||
| 38 | /** |
||
| 39 | * {@inheritdoc} |
||
| 40 | */ |
||
| 41 | 1 | public function __toString(): string |
|
| 42 | { |
||
| 43 | 1 | return $this->string(); |
|
| 44 | } |
||
| 45 | |||
| 46 | /** |
||
| 47 | * Get the string value. |
||
| 48 | * |
||
| 49 | * @return string |
||
| 50 | */ |
||
| 51 | 50 | public function string(): string |
|
| 54 | } |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Check whether string is valid for the concrete type. |
||
| 58 | * |
||
| 59 | * @param string $string |
||
| 60 | * |
||
| 61 | * @return bool |
||
| 62 | */ |
||
| 63 | 69 | protected function _validateString(string $string): bool |
|
| 67 | } |
||
| 68 | } |
||
| 69 |