Total Complexity | 6 |
Total Lines | 52 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
15 | class CountryCode |
||
16 | { |
||
17 | public const BGR = 100; |
||
18 | public const ROU = 642; |
||
19 | public const GBR = 826; |
||
20 | |||
21 | public const CODES = [ |
||
22 | self::BGR, |
||
23 | self::ROU, |
||
24 | self::GBR, |
||
25 | ]; |
||
26 | |||
27 | /** |
||
28 | * Current ISO 3166 country numeric code. |
||
29 | */ |
||
30 | private int $code; |
||
31 | |||
32 | 6 | public function __construct(int $code) |
|
33 | { |
||
34 | 6 | $this->setCode($code); |
|
35 | } |
||
36 | |||
37 | /** |
||
38 | * @todo Implement the logic for checking if $this and $other are equals |
||
39 | */ |
||
40 | 2 | public function equals(self $other): bool |
|
41 | { |
||
42 | // you can try make it with one line of code |
||
43 | 2 | return $this->getCode() === $other->getCode(); |
|
44 | } |
||
45 | |||
46 | 6 | public function setCode(int $code): self |
|
47 | { |
||
48 | 6 | if (! \in_array($code, self::CODES)) { |
|
49 | 1 | throw new \InvalidArgumentException(); |
|
50 | } |
||
51 | 5 | $this->code = $code; |
|
52 | |||
53 | 5 | return $this; |
|
54 | } |
||
55 | |||
56 | /** |
||
57 | * @return int code |
||
58 | */ |
||
59 | 2 | public function getCode(): int |
|
62 | } |
||
63 | |||
64 | 1 | public function toArray(): array |
|
67 | } |
||
68 | } |
||
69 |