1 | <?php |
||
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() |
||
81 | |||
82 | /** |
||
83 | * Get id. |
||
84 | * |
||
85 | * @return int |
||
86 | */ |
||
87 | 1 | public function getId() |
|
91 | |||
92 | /** |
||
93 | * Set type. |
||
94 | * |
||
95 | * @param $type |
||
96 | * |
||
97 | * @return FormRequest |
||
98 | */ |
||
99 | public function setType($type) |
||
107 | |||
108 | /** |
||
109 | * Get type. |
||
110 | * |
||
111 | * @return string |
||
112 | */ |
||
113 | 1 | public function getType() |
|
117 | |||
118 | /** |
||
119 | * Set status. |
||
120 | * |
||
121 | * @param string $status |
||
122 | * |
||
123 | * @return FormRequest |
||
124 | */ |
||
125 | public function setStatus($status) |
||
133 | |||
134 | /** |
||
135 | * Get status. |
||
136 | * |
||
137 | * @return string |
||
138 | */ |
||
139 | 1 | public function getStatus() |
|
143 | |||
144 | /** |
||
145 | * Set user. |
||
146 | * |
||
147 | * @param User $user |
||
148 | * |
||
149 | * @return FormRequest |
||
150 | */ |
||
151 | public function setUser(User $user) |
||
157 | |||
158 | /** |
||
159 | * Get user. |
||
160 | * |
||
161 | * @return User |
||
162 | */ |
||
163 | public function getUser() |
||
167 | |||
168 | /** |
||
169 | * Set date. |
||
170 | * |
||
171 | * @param \DateTime $date |
||
172 | * |
||
173 | * @return FormRequest |
||
174 | */ |
||
175 | public function setDate($date) |
||
176 | { |
||
177 | try { |
||
178 | $this->date = \DateTime::createFromFormat(\DATE_RFC3339, $date); |
||
|
|||
179 | } catch (\Exception $e) { |
||
180 | $this->date = false; |
||
181 | } |
||
182 | |||
183 | return $this; |
||
184 | } |
||
185 | /** |
||
186 | * Get date. |
||
187 | * |
||
188 | * @return \DateTime |
||
189 | */ |
||
190 | 1 | public function getDate() |
|
194 | |||
195 | /** |
||
196 | * @return string |
||
197 | */ |
||
198 | 1 | public function getReason() |
|
202 | |||
203 | /** |
||
204 | * @param string $reason |
||
205 | * |
||
206 | * @return $this |
||
207 | */ |
||
208 | public function setReason($reason) |
||
214 | } |
||
215 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.