These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace AppBundle\Entity; |
||
4 | |||
5 | |||
6 | /** |
||
7 | * Post class. |
||
8 | */ |
||
9 | class Post |
||
10 | { |
||
11 | /** |
||
12 | * @var string |
||
13 | */ |
||
14 | private $file; |
||
15 | |||
16 | /** |
||
17 | * @var string |
||
18 | */ |
||
19 | private $title; |
||
20 | |||
21 | /** |
||
22 | * @var string |
||
23 | */ |
||
24 | private $intro; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $readTime; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $content; |
||
35 | |||
36 | /** |
||
37 | * @var string |
||
38 | */ |
||
39 | private $slug; |
||
40 | |||
41 | /** |
||
42 | * @var int |
||
43 | */ |
||
44 | private $num; |
||
45 | |||
46 | /** |
||
47 | * @var \DateTime |
||
48 | */ |
||
49 | private $created; |
||
50 | |||
51 | /** |
||
52 | * @var \DateTime |
||
53 | */ |
||
54 | private $updated; |
||
55 | |||
56 | /** |
||
57 | * Set file |
||
58 | * |
||
59 | * @param string $file |
||
60 | * @return Post |
||
61 | */ |
||
62 | public function setFile($file) |
||
63 | { |
||
64 | $this->file = $file; |
||
65 | |||
66 | return $this; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * Get file |
||
71 | * |
||
72 | * @return string |
||
73 | */ |
||
74 | public function getFile() |
||
75 | { |
||
76 | return $this->file; |
||
77 | } |
||
78 | |||
79 | /** |
||
80 | * Set title |
||
81 | * |
||
82 | * @param string $title |
||
83 | * @return Post |
||
84 | */ |
||
85 | public function setTitle($title) |
||
86 | { |
||
87 | $this->title = $title; |
||
88 | |||
89 | return $this; |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Get title |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | public function getTitle() |
||
98 | { |
||
99 | return $this->title; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Set intro |
||
104 | * |
||
105 | * @param string $intro |
||
106 | * @return Post |
||
107 | */ |
||
108 | public function setIntro($intro) |
||
109 | { |
||
110 | $this->intro = $intro; |
||
111 | |||
112 | return $this; |
||
113 | } |
||
114 | |||
115 | /** |
||
116 | * Get intro |
||
117 | * |
||
118 | * @return string |
||
119 | */ |
||
120 | public function getIntro() |
||
121 | { |
||
122 | return $this->intro; |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Set content |
||
127 | * |
||
128 | * @param string $content |
||
129 | * @return Post |
||
130 | */ |
||
131 | public function setContent($content) |
||
132 | { |
||
133 | $this->content = $content; |
||
134 | |||
135 | return $this; |
||
136 | } |
||
137 | |||
138 | /** |
||
139 | * Get content |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | public function getContent() |
||
144 | { |
||
145 | return $this->content; |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Set slug |
||
150 | * |
||
151 | * @param string $slug |
||
152 | * @return Post |
||
153 | */ |
||
154 | public function setSlug($slug) |
||
155 | { |
||
156 | $this->slug = $slug; |
||
157 | |||
158 | return $this; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * Get slug |
||
163 | * |
||
164 | * @return string |
||
165 | */ |
||
166 | public function getSlug() |
||
167 | { |
||
168 | return $this->slug; |
||
169 | } |
||
170 | |||
171 | /** |
||
172 | * @param string $date |
||
173 | */ |
||
174 | public function setCreated($date) |
||
175 | { |
||
176 | $this->created = \DateTime::createFromFormat('Y-m-d', $date); |
||
0 ignored issues
–
show
|
|||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @return \DateTime |
||
181 | */ |
||
182 | public function getCreated() |
||
183 | { |
||
184 | return $this->created; |
||
185 | } |
||
186 | |||
187 | /** |
||
188 | * @param string $date |
||
189 | */ |
||
190 | public function setUpdated($date) |
||
191 | { |
||
192 | $this->updated = \DateTime::createFromFormat('Y-m-d', $date); |
||
0 ignored issues
–
show
It seems like
\DateTime::createFromFormat('Y-m-d', $date) can also be of type false . However, the property $updated is declared as type object<DateTime> . Maybe add an additional type check?
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 Either this assignment is in error or a type check should be added for that assignment. class Id
{
public $id;
public function __construct($id)
{
$this->id = $id;
}
}
class Account
{
/** @var Id $id */
public $id;
}
$account_id = false;
if (starsAreRight()) {
$account_id = new Id(42);
}
$account = new Account();
if ($account instanceof Id)
{
$account->id = $account_id;
}
Loading history...
|
|||
193 | } |
||
194 | |||
195 | /** |
||
196 | * @return \DateTime |
||
197 | */ |
||
198 | public function getUpdated() |
||
199 | { |
||
200 | return $this->updated; |
||
201 | } |
||
202 | |||
203 | /** |
||
204 | * Set num |
||
205 | * |
||
206 | * @param int $id |
||
207 | * @return Post |
||
208 | */ |
||
209 | public function setNum($id) |
||
210 | { |
||
211 | $this->num = $id; |
||
212 | |||
213 | return $this; |
||
214 | } |
||
215 | |||
216 | /** |
||
217 | * Get num |
||
218 | * |
||
219 | * @return string |
||
220 | */ |
||
221 | public function getNum() |
||
222 | { |
||
223 | return $this->num; |
||
224 | } |
||
225 | |||
226 | /** |
||
227 | * Set read time |
||
228 | * |
||
229 | * @param string $readTime |
||
230 | * @return Post |
||
231 | */ |
||
232 | public function setReadTime($readTime) |
||
233 | { |
||
234 | $this->readTime = $readTime; |
||
235 | |||
236 | return $this; |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Get read time |
||
241 | * |
||
242 | * @return string |
||
243 | */ |
||
244 | public function getReadTime() |
||
245 | { |
||
246 | return $this->readTime; |
||
247 | } |
||
248 | |||
249 | } |
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.