HistoryCard::createFromArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TrelloCycleTime\ValueObject;
6
7
class HistoryCard
8
{
9
    /**
10
     * @var string
11
     */
12
    private $id;
13
    /**
14
     * @var string
15
     */
16
    private $title;
17
    /**
18
     * @var string|null
19
     */
20
    private $from;
21
    /**
22
     * @var string
23
     */
24
    private $to;
25
    /**
26
     * @var string
27
     */
28
    private $date;
29
30 4
    private function __construct(string $id, string $title, ?string $from, string $to, string $date)
31
    {
32 4
        $this->id = $id;
33 4
        $this->title = $title;
34 4
        $this->from = $from;
35 4
        $this->to = $to;
36 4
        $this->date = $date;
37 4
    }
38
39 4
    public static function createFromArray(array $data) :HistoryCard
40
    {
41 4
        $id = $data['data']['card']['id'];
42 4
        $title = $data['data']['card']['name'];
43 4
        $from = $data['data']['listBefore']['name'];
44 4
        $to = $data['data']['listAfter']['name'];
45 4
        $date = date('Y-m-d H:i:s', strtotime($data['date']));
46
47 4
        return new self($id, $title, $from, $to, $date);
48
    }
49
50 2
    public static function createFromCreationArray(array $data) :HistoryCard
51
    {
52 2
        $id = $data['data']['card']['id'];
53 2
        $title = $data['data']['card']['name'];
54 2
        $from = null;
55 2
        $to = $data['data']['list']['name'];
56 2
        $date = date('Y-m-d H:i:s', strtotime($data['date']));
57
58 2
        return new self($id, $title, $from, $to, $date);
59
    }
60
61
    /**
62
     * @return string
63
     */
64 3
    public function getId(): string
65
    {
66 3
        return $this->id;
67
    }
68
69
    /**
70
     * @return string
71
     */
72 3
    public function getTitle(): string
73
    {
74 3
        return $this->title;
75
    }
76
77
    /**
78
     * @return string
79
     */
80 3
    public function getFrom(): ?string
81
    {
82 3
        return $this->from;
83
    }
84
85
    /**
86
     * @return string
87
     */
88 3
    public function getTo(): string
89
    {
90 3
        return $this->to;
91
    }
92
93
    /**
94
     * @return string
95
     */
96 3
    public function getDate(): string
97
    {
98 3
        return $this->date;
99
    }
100
}