Completed
Push — master ( 6990a8...a32328 )
by Aurimas
10s
created

PickupPoint::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Omniva;
4
5
class PickupPoint
6
{
7
    const TYPE_TERMINAL = 0;
8
    const TYPE_POST_OFFICE = 1;
9
10
    private $type;
11
    private $identifier;
12
13
    public function __construct(string $identifier)
14
    {
15
        $this->identifier = $identifier;
16
    }
17
18
    public function setIdentifier(string $identifier): self
19
    {
20
        $this->identifier = $identifier;
21
        return $this;
22
    }
23
24
    public function getIdentifier(): string
25
    {
26
        return $this->identifier;
27
    }
28
29
    public function setType(int $type): self
30
    {
31
        if (!in_array($type, [self::TYPE_TERMINAL, self::TYPE_POST_OFFICE])) {
32
            throw new \InvalidArgumentException('Unsupported type');
33
        }
34
35
        $this->type = $type;
36
        return $this;
37
    }
38
39
    public function getType(): ?int
40
    {
41
        return $this->type;
42
    }
43
44
    public function isPostOffice(): bool
45
    {
46
        $this->guardAgainstEmptyType();
47
        return $this->getType() === self::TYPE_POST_OFFICE;
48
    }
49
50
    public function isTerminal(): bool
51
    {
52
        $this->guardAgainstEmptyType();
53
        return $this->getType() === self::TYPE_TERMINAL;
54
    }
55
56
    private function guardAgainstEmptyType(): void
57
    {
58
        if ($this->getType() === null) {
59
            throw new \RuntimeException('No type has been provided');
60
        }
61
    }
62
}
63