CountryCode::equals()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace VasilDakov\Speedy\Model;
6
7
/**
8
 * Class CountryCode.
9
 *
10
 * @author Vasil Dakov <[email protected]>
11
 * @copyright 2009-2022 Neutrino.bg
12
 *
13
 * @version 1.0
14
 */
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
60
    {
61 2
        return $this->code;
62
    }
63
64 1
    public function toArray(): array
65
    {
66 1
        return [];
67
    }
68
}
69