Element::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 5
nc 2
nop 3
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace DH\NavigationBundle\Model\DistanceMatrix;
4
5
use DH\NavigationBundle\Model\Distance;
6
use DH\NavigationBundle\Model\Duration;
7
8
class Element
9
{
10
    public const STATUS_OK = 'OK';
11
    public const STATUS_FAILED = 'failed';
12
    public const STATUS_NOT_FOUND = 'NOT_FOUND';
13
    public const STATUS_ZERO_RESULTS = 'ZERO_RESULTS';
14
15
    public const STATUS = [
16
        self::STATUS_OK,
17
        self::STATUS_FAILED,
18
        self::STATUS_NOT_FOUND,
19
        self::STATUS_ZERO_RESULTS,
20
    ];
21
22
    /**
23
     * @var string
24
     */
25
    private $status;
26
27
    /**
28
     * @var ?Duration
29
     */
30
    private $duration;
31
32
    /**
33
     * @var ?Distance
34
     */
35
    private $distance;
36
37
    /**
38
     * Element constructor.
39
     *
40
     * @throws \Exception
41
     */
42
    public function __construct(string $status, ?Duration $duration, ?Distance $distance)
43
    {
44
        if (!\in_array($status, self::STATUS, true)) {
45
            throw new \Exception(sprintf('Unknown status code: %s', $status));
46
        }
47
48
        $this->status = $status;
49
        $this->duration = $duration;
50
        $this->distance = $distance;
51
    }
52
53
    public function getStatus(): string
54
    {
55
        return $this->status;
56
    }
57
58
    public function getDuration(): ?Duration
59
    {
60
        return $this->duration;
61
    }
62
63
    public function getDistance(): ?Distance
64
    {
65
        return $this->distance;
66
    }
67
}
68