Test Failed
Pull Request — master (#1)
by Daniel
07:34 queued 01:51
created

Task::changeName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
namespace Todo\Domain;
4
5
/**
6
 * Class Task
7
 *
8
 * Task object definition
9
 *
10
 * @category None
11
 * @package  Todo\Domain
12
 * @author   Martin Pham <[email protected]>
13
 * @license  None http://
14
 * @link     None
15
 */
16
class Task implements \JsonSerializable
17
{
18
    /**
19
     * Task's statuses
20
     */
21
    const STATUS_REMAINING = 'remaining';
22
    const STATUS_COMPLETED = 'completed';
23
24
    /**
25
     * Id
26
     *
27
     * @var mixed
28
     */
29
    protected $id;
30
31
    /**
32
     * Name
33
     *
34
     * @var string
35
     */
36
    protected $name;
37
38
    /**
39
     * Status
40
     * We want default Task's status is remaining
41
     *
42
     * @var string
43
     */
44
    protected $status = Task::STATUS_REMAINING;
45
46
    /**
47
     * Created time
48
     *
49
     * @var \DateTime
50
     */
51
    protected $createdAt;
52
53
    /**
54
     * Updated time
55
     *
56
     * @var \DateTime
57
     */
58
    protected $updatedAt;
59
60
    /**
61
     * @param string $name
62
     */
63
    public function __construct(string $name)
64
    {
65
        $this->name = $name;
66
        $this->createdAt = new \DateTime();
67
        $this->status = self::STATUS_REMAINING;
68
    }
69
70
    /**
71
     * Get Id
72
     *
73
     * @return mixed
74
     */
75
    public function getId()
76
    {
77
        return $this->id;
78
    }
79
80
    /**
81
     * Set Id
82
     *
83
     * @param mixed $id Id
84
     */
85
    public function setId($id)
86
    {
87
        $this->id = $id;
88
    }
89
90
    /**
91
     * Get Name
92
     *
93
     * @return mixed
94
     */
95
    public function getName()
96
    {
97
        return $this->name;
98
    }
99
100
    /**
101
     * Set Name
102
     *
103
     * @param mixed $name Name
104
     */
105
    public function changeName($name)
106
    {
107
        $this->name = $name;
108
        $this->updatedAt = new \DateTime();
109
    }
110
111
    /**
112
     * Get Status
113
     *
114
     * @return mixed
115
     */
116
    public function getStatus()
117
    {
118
        return $this->status;
119
    }
120
121
    /**
122
     * Get CreatedAt
123
     *
124
     * @return mixed
125
     */
126
    public function getCreatedAt()
127
    {
128
        return $this->createdAt;
129
    }
130
    
131
132
    /**
133
     * Get UpdatedAt
134
     *
135
     * @return mixed
136
     */
137
    public function getUpdatedAt()
138
    {
139
        return $this->updatedAt;
140
    }
141
142
    /**
143
     * Completes the task
144
     */
145
    public function complete()
146
    {
147
        $this->status = self::STATUS_COMPLETED;
148
        $this->updatedAt = new \DateTime();
149
    }
150
151
    /**
152
     * @inheritDoc
153
     */
154
    public function jsonSerialize()
155
    {
156
        return [
157
            'id' => $this->getId(),
158
            'name' => $this->getName(),
159
            'status' => $this->getStatus()
160
        ];
161
    }
162
}
163