| 1 | <?php |
||
| 12 | final class NameItem implements ItemInterface |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var string |
||
| 16 | */ |
||
| 17 | private $name; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * |
||
| 21 | */ |
||
| 22 | private CONST VALID_CHAR = "ABCDEFGHIJKLMNOPQRSTUVWXYZ.+-"; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * NameItem constructor. |
||
| 26 | * @param string $name |
||
| 27 | */ |
||
| 28 | 26 | public function __construct(string $name) |
|
| 29 | { |
||
| 30 | 26 | if (strlen($name) !== strspn($name, self::VALID_CHAR)) { |
|
| 31 | 1 | throw new \InvalidArgumentException('name can only contain uppercase A-Z chars'); |
|
| 32 | } |
||
| 33 | |||
| 34 | 25 | $this->name = $name; |
|
| 35 | 25 | } |
|
| 36 | |||
| 37 | /** |
||
| 38 | * @return string |
||
| 39 | */ |
||
| 40 | 22 | public function getName(): string |
|
| 44 | |||
| 45 | /** |
||
| 46 | * @return string |
||
| 47 | */ |
||
| 48 | 7 | public function __toString(): string |
|
| 52 | } |