CycleTime::getDays()   A
last analyzed

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
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace TrelloCycleTime\ValueObject;
6
7
8
class CycleTime implements \JsonSerializable
9
{
10
    /**
11
     * @var string
12
     */
13
    private $from;
14
    /**
15
     * @var string
16
     */
17
    private $to;
18
    /**
19
     * @var float|null
20
     */
21
    private $days;
22
    /**
23
     * @var string
24
     */
25
    private $name;
26
27 6
    private function __construct(string $from, string $to, ?float $days, string $name)
28
    {
29 6
        $this->from = $from;
30 6
        $this->to = $to;
31 6
        $this->days = $days;
32 6
        $this->name = $name;
33 6
    }
34
35 5
    public static function createFromCardHistory(HistoryCard $cardHistory): CycleTime
36
    {
37 5
        $from = $cardHistory->getFrom() ?? '';
38 5
        $to = $cardHistory->getTo();
39 5
        $name = $from . '_' . $to;
40 5
        $days = null;
41
42 5
        return new self($from, $to, $days, $name);
43
    }
44
45 3
    public static function createWithDays(string $from, string $to, float $days): CycleTime
46
    {
47 3
        $name = $from . '_' . $to;
48
49 3
        return new self($from, $to, $days, $name);
50
    }
51
52
    /**
53
     * @return string
54
     */
55 3
    public function getFrom(): string
56
    {
57 3
        return $this->from;
58
    }
59
60
    /**
61
     * @return string
62
     */
63 3
    public function getTo(): string
64
    {
65 3
        return $this->to;
66
    }
67
68
    /**
69
     * @return float
70
     */
71 2
    public function getDays(): ?float
72
    {
73 2
        return $this->days;
74
    }
75
76
    public function setDays(float $days) :?float
77
    {
78
        return $this->days = $days;
79
    }
80
81
    /**
82
     * @return string
83
     */
84 4
    public function getName(): string
85
    {
86 4
        return $this->name;
87
    }
88
89
    /**
90
     * Specify data which should be serialized to JSON
91
     * @link https://php.net/manual/en/jsonserializable.jsonserialize.php
92
     * @return mixed data which can be serialized by <b>json_encode</b>,
93
     * which is a value of any type other than a resource.
94
     * @since 5.4.0
95
     */
96 2
    public function jsonSerialize()
97
    {
98
        return [
99 2
            'from' => $this->from,
100 2
            'to' => $this->to,
101 2
            'days' => $this->days,
102 2
            'name' => $this->name
103
        ];
104
    }
105
}