PickupPoint   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 20
dl 0
loc 55
c 0
b 0
f 0
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getType() 0 3 1
A setIdentifier() 0 4 1
A getIdentifier() 0 3 1
A isPostOffice() 0 4 1
A setType() 0 8 2
A guardAgainstEmptyType() 0 4 2
A isTerminal() 0 4 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