Passed
Push — master ( a8bcd9...c4920e )
by Alessandro
57s queued 10s
created

CycleTime::setDays()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
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
20
     */
21
    private $days;
22
    /**
23
     * @var string
24
     */
25
    private $name;
26
27 5
    private function __construct(string $from, string $to, ?float $days, string $name)
28
    {
29 5
        $this->from = $from;
30 5
        $this->to = $to;
31 5
        $this->days = $days;
32 5
        $this->name = $name;
33 5
    }
34
35 4
    public static function createFromCardHistory(HistoryCard $cardHistory): CycleTime
36
    {
37 4
        $from = $cardHistory->getFrom();
38 4
        $to = $cardHistory->getTo();
39 4
        $name = $from . '_' . $to;
40 4
        $days = null;
41
42 4
        return new self($from, $to, $days, $name);
43
    }
44
45 2
    public static function createWithDays(string $from, string $to, float $days): CycleTime
46
    {
47 2
        $name = $from . '_' . $to;
48
49 2
        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(string $days)
77
    {
78
        return $this->days = $days;
0 ignored issues
show
Documentation Bug introduced by
The property $days was declared of type double, but $days is of type string. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
79
    }
80
81
    /**
82
     * @return string
83
     */
84 3
    public function getName(): string
85
    {
86 3
        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 1
    public function jsonSerialize()
97
    {
98
        return [
99 1
            'from' => $this->from,
100 1
            'to' => $this->to,
101 1
            'days' => $this->days,
102 1
            'name' => $this->name
103
        ];
104
    }
105
}