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

PackageStatus::getDate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 0
crap 1
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