CountryCode   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 52
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getCode() 0 3 1
A setCode() 0 8 2
A toArray() 0 3 1
A equals() 0 4 1
A __construct() 0 3 1
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