Total Complexity | 9 |
Total Lines | 51 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
10 | class District implements AddressElement |
||
11 | { |
||
12 | /** @var string */ |
||
13 | private $name; |
||
14 | |||
15 | /** |
||
16 | * @throws \InvalidArgumentException if supplied value is invalid. |
||
17 | */ |
||
18 | public function __construct(string $name) |
||
19 | { |
||
20 | $this->setName($name); |
||
21 | } |
||
22 | |||
23 | private function setName(string $name) : void |
||
24 | { |
||
25 | $normalized = StringUtils::trimSpacesWisely($name); |
||
26 | if (empty($normalized)) { |
||
27 | throw new \InvalidArgumentException(sprintf('The value "%s" is not a valid district name.', $name)); |
||
28 | } |
||
29 | |||
30 | $this->name = StringUtils::convertCaseToTitle($normalized); |
||
31 | } |
||
32 | |||
33 | public function getName() : string |
||
34 | { |
||
35 | return $this->name; |
||
36 | } |
||
37 | |||
38 | public function equals(?ValueObject $object) : bool |
||
39 | { |
||
40 | if (! $object instanceof self) { |
||
41 | return false; |
||
42 | } |
||
43 | |||
44 | return $object->getName() === $this->getName(); |
||
45 | } |
||
46 | |||
47 | public function getFormatted() : string |
||
50 | } |
||
51 | |||
52 | public function __toString() : string |
||
53 | { |
||
55 | } |
||
56 | |||
57 | public function jsonSerialize() |
||
64 |