Completed
Push — dev ( 8c0d10...068048 )
by
unknown
04:34 queued 04:29
created

FormRequest::setReason()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 3
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
namespace AppBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Knp\DoctrineBehaviors\Model as ORMBehaviors;
7
use Symfony\Component\Serializer\Annotation\Groups;
8
use Symfony\Component\Validator\Constraints as Assert;
9
10
/**
11
 * FormRequest.
12
 *
13
 * @ORM\Entity(repositoryClass="AppBundle\Repository\FormRequestRepository")
14
 */
15
class FormRequest
16
{
17
    use ORMBehaviors\Timestampable\Timestampable;
18
19
    const STATUS = ['pending', 'approved', 'rejected'];
20
    const TYPE = ['personal day', 'overnight guest', 'sick day'];
21
22
    /**
23
     * @var int
24
     *
25
     * @ORM\Column(name="id", type="integer")
26
     * @ORM\Id
27
     * @ORM\GeneratedValue(strategy="AUTO")
28
     */
29
    private $id;
30
31
    /**
32
     * @var string
33
     * @Assert\NotBlank()
34
     * @Assert\Choice(FormRequest::TYPE)
35
     * @ORM\Column(type="string", length=25)
36
     * @Groups({"Detail"})
37
     */
38
    private $type;
39
40
    /**
41
     * @var string
42
     * @Assert\NotBlank()
43
     * @Assert\Type("string")
44
     * @Assert\Length(
45
     *      max = 255
46
     * )
47
     * @ORM\Column(type="string", length=255)
48
     * @Groups({"Detail"})
49
     */
50
    private $status;
51
52
    /**
53
     * @var User
54
     * @Assert\Type("object")
55
     * @Assert\Valid
56
     * @ORM\ManyToOne(targetEntity="User", inversedBy="formRequests")
57
     */
58
    private $user;
59
60
    /**
61
     * @var \DateTime
62
     * @Assert\DateTime()
63
     * @ORM\Column(type="datetime")
64
     * @Groups({"Detail"})
65
     */
66
    private $date;
67
68
    /**
69
     * @var string
70
     *
71
     * @ORM\Column(type="string", nullable=true)
72
     * @Assert\Length(min="5", max="100")
73
     * @Groups({"Detail"})
74
     */
75
    private $reason;
76
77
    public function __construct()
78
    {
79
        $this->setStatus('pending');
80
    }
81
82
    /**
83
     * Get id.
84
     *
85
     * @return int
86
     */
87 1
    public function getId()
88
    {
89 1
        return $this->id;
90
    }
91
92
    /**
93
     * Set type.
94
     *
95
     * @param $type
96
     *
97
     * @return FormRequest
98
     */
99
    public function setType($type)
100
    {
101
        if (in_array($type, self::TYPE)) {
102
            $this->type = $type;
103
        }
104
105
        return $this;
106
    }
107
108
    /**
109
     * Get type.
110
     *
111
     * @return string
112
     */
113 1
    public function getType()
114
    {
115 1
        return $this->type;
116
    }
117
118
    /**
119
     * Set status.
120
     *
121
     * @param string $status
122
     *
123
     * @return FormRequest
124
     */
125
    public function setStatus($status)
126
    {
127
        if (in_array($status, self::STATUS)) {
128
            $this->status = $status;
129
        }
130
131
        return $this;
132
    }
133
134
    /**
135
     * Get status.
136
     *
137
     * @return string
138
     */
139 1
    public function getStatus()
140
    {
141 1
        return $this->status;
142
    }
143
144
    /**
145
     * Set user.
146
     *
147
     * @param User $user
148
     *
149
     * @return FormRequest
150
     */
151
    public function setUser(User $user)
152
    {
153
        $this->user = $user;
154
155
        return $this;
156
    }
157
158
    /**
159
     * Get user.
160
     *
161
     * @return User
162
     */
163
    public function getUser()
164
    {
165
        return $this->user;
166
    }
167
168
    /**
169
     * Set date.
170
     *
171
     * @param \DateTime $date
172
     *
173
     * @return FormRequest
174
     */
175
    public function setDate($date)
176
    {
177
        $this->date = new \DateTime($date);
178
179
        return $this;
180
    }
181
    /**
182
     * Get date.
183
     *
184
     * @return \DateTime
185
     */
186 1
    public function getDate()
187
    {
188 1
        return $this->date;
189
    }
190
191
    /**
192
     * @return string
193
     */
194 1
    public function getReason()
195
    {
196 1
        return $this->reason;
197
    }
198
199
    /**
200
     * @param string $reason
201
     *
202
     * @return $this
203
     */
204
    public function setReason($reason)
205
    {
206
        $this->reason = $reason;
207
208
        return $this;
209
    }
210
}
211