Completed
Push — master ( 0512a1...7c8694 )
by Tomáš
03:46
created

PackageStatus   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 71
c 0
b 0
f 0
wmc 7
lcom 0
cbo 0
rs 10
ccs 16
cts 16
cp 1

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getName() 0 4 1
A getDate() 0 4 1
A newInstanceFromData() 0 10 3
1
<?php
2
3
namespace Inspirum\Balikobot\Model\Values;
4
5
use DateTime;
6
use Throwable;
7
8
class PackageStatus
9
{
10
    /**
11
     * @var int
12
     */
13
    private $id;
14
15
    /**
16
     * @var string
17
     */
18
    private $name;
19
20
    /**
21
     * @var \DateTime|null
22
     */
23
    private $date;
24
25
    /**
26
     * PackageStatus constructor
27
     *
28
     * @param int            $id
29
     * @param string         $name
30
     * @param \DateTime|null $date
31
     */
32 10
    public function __construct(int $id, string $name, DateTime $date = null)
33
    {
34 10
        $this->id   = $id;
35 10
        $this->name = $name;
36 10
        $this->date = $date;
37 10
    }
38
39
    /**
40
     * @return int
41
     */
42 6
    public function getId(): int
43
    {
44 6
        return $this->id;
45
    }
46
47
    /**
48
     * @return string
49
     */
50 6
    public function getName(): string
51
    {
52 6
        return $this->name;
53
    }
54
55
    /**
56
     * @return \DateTime|null
57
     */
58 6
    public function getDate(): ?DateTime
59
    {
60 6
        return $this->date;
61
    }
62
63
    /**
64
     * @param array<string,mixed> $data
65
     *
66
     * @return \Inspirum\Balikobot\Model\Values\PackageStatus
67
     */
68 10
    public static function newInstanceFromData(array $data): self
69
    {
70
        try {
71 10
            $date = $data['date'] ? new DateTime($data['date']) : null;
72 1
        } catch (Throwable $exception) {
73 1
            $date = null;
74
        }
75
76 10
        return new self($data['status_id'], $data['name'], $date);
77
    }
78
}
79