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 Kunstmaan\TranslatorBundle\Entity; |
||
4 | |||
5 | use DateTime; |
||
6 | use Doctrine\ORM\Mapping as ORM; |
||
7 | use Kunstmaan\TranslatorBundle\Model\Translation as TranslationModel; |
||
8 | use Symfony\Component\Validator\Constraints as Assert; |
||
9 | |||
10 | /** |
||
11 | * @ORM\Entity(repositoryClass="Kunstmaan\TranslatorBundle\Repository\TranslationRepository") |
||
12 | * @ORM\Table( |
||
13 | * name="kuma_translation", |
||
14 | * uniqueConstraints={ |
||
15 | * @ORM\UniqueConstraint(name="keyword_per_locale", columns={"keyword", "locale", "domain"}), |
||
16 | * @ORM\UniqueConstraint(name="translation_id_per_locale", columns={"translation_id", "locale"}), |
||
17 | * }, |
||
18 | * indexes={@ORM\Index(name="idx_translation_locale_domain", columns={"locale", "domain"})} |
||
19 | * ) |
||
20 | * @ORM\HasLifecycleCallbacks |
||
21 | */ |
||
22 | class Translation |
||
23 | { |
||
24 | const FLAG_NEW = 'new'; |
||
25 | const FLAG_UPDATED = 'updated'; |
||
26 | const STATUS_DEPRECATED = 'deprecated'; |
||
27 | const STATUS_DISABLED = 'disabled'; |
||
28 | const STATUS_ENABLED = 'enabled'; |
||
29 | |||
30 | /** |
||
31 | * @ORM\Id |
||
32 | * @ORM\Column(type="integer") |
||
33 | * @ORM\GeneratedValue(strategy="AUTO") |
||
34 | */ |
||
35 | protected $id; |
||
36 | |||
37 | /** |
||
38 | * @ORM\Column(type="integer", name="translation_id", nullable=true) |
||
39 | * @Assert\NotBlank() |
||
40 | */ |
||
41 | protected $translationId; |
||
42 | |||
43 | /** |
||
44 | * The translations keyword to use in your template or call from the translator |
||
45 | * |
||
46 | * @ORM\Column(type="string", nullable=true) |
||
47 | * @Assert\NotBlank() |
||
48 | */ |
||
49 | protected $keyword; |
||
50 | |||
51 | /** |
||
52 | * The translations keyword to use in your template or call from the translator |
||
53 | * |
||
54 | * @ORM\Column(type="string", length=5, nullable=true) |
||
55 | * @Assert\NotBlank() |
||
56 | */ |
||
57 | protected $locale; |
||
58 | |||
59 | /** |
||
60 | * @var string |
||
61 | * The translations deprecation date |
||
62 | * |
||
63 | * @ORM\column(type="string", length=10, options={"default" : "enabled"}) |
||
64 | */ |
||
65 | protected $status = self::STATUS_ENABLED; |
||
66 | |||
67 | /** |
||
68 | * Location where the translation comes from |
||
69 | * |
||
70 | * @ORM\Column(type="string", length=50, nullable=true) |
||
71 | */ |
||
72 | protected $file; |
||
73 | |||
74 | /** |
||
75 | * Translation |
||
76 | * |
||
77 | * @var string |
||
78 | * @ORM\Column(type="text", nullable=true) |
||
79 | * @Assert\NotBlank() |
||
80 | */ |
||
81 | protected $text; |
||
82 | |||
83 | /** |
||
84 | * @ORM\Column(type="string", length=30, nullable=true) |
||
85 | * @Assert\NotBlank() |
||
86 | */ |
||
87 | protected $domain; |
||
88 | |||
89 | /** |
||
90 | * @var \DateTime |
||
91 | * |
||
92 | * @ORM\Column(type="datetime", name="created_at", nullable=true) |
||
93 | */ |
||
94 | protected $createdAt; |
||
95 | |||
96 | /** |
||
97 | * @var \DateTime |
||
98 | * |
||
99 | * @ORM\Column(type="datetime", name="updated_at", nullable=true) |
||
100 | */ |
||
101 | protected $updatedAt; |
||
102 | |||
103 | /** |
||
104 | * A flag which defines the status of a specific translations ('updated', 'new', ..) |
||
105 | * |
||
106 | * @var string |
||
107 | * |
||
108 | * @ORM\Column(type="string", length=20, nullable=true) |
||
109 | */ |
||
110 | protected $flag; |
||
111 | |||
112 | /** |
||
113 | * @ORM\PrePersist |
||
114 | */ |
||
115 | 12 | View Code Duplication | public function prePersist() |
116 | { |
||
117 | 12 | $this->createdAt = new DateTime(); |
|
118 | 12 | $this->updatedAt = new DateTime(); |
|
119 | 12 | $this->flag = self::FLAG_NEW; |
|
120 | |||
121 | 12 | return $this->id; |
|
122 | } |
||
123 | |||
124 | /** |
||
125 | * @ORM\PreUpdate |
||
126 | */ |
||
127 | 4 | View Code Duplication | public function preUpdate() |
128 | { |
||
129 | 4 | $this->updatedAt = new DateTime(); |
|
130 | |||
131 | 4 | if ($this->flag === null) { |
|
132 | 3 | $this->flag = self::FLAG_UPDATED; |
|
133 | } |
||
134 | 4 | } |
|
135 | |||
136 | /** |
||
137 | * @return string |
||
138 | */ |
||
139 | 1 | public function getId() |
|
140 | { |
||
141 | 1 | return $this->id; |
|
142 | } |
||
143 | |||
144 | /** |
||
145 | * @param string $id |
||
146 | * |
||
147 | * @return Translation |
||
148 | */ |
||
149 | 3 | public function setId($id) |
|
150 | { |
||
151 | 3 | $this->id = $id; |
|
152 | |||
153 | 3 | return $this; |
|
154 | } |
||
155 | |||
156 | /** |
||
157 | * @return string |
||
158 | */ |
||
159 | 6 | public function getKeyword() |
|
160 | { |
||
161 | 6 | return $this->keyword; |
|
162 | } |
||
163 | |||
164 | /** |
||
165 | * @param string $keyword |
||
166 | * |
||
167 | * @return Translation |
||
168 | */ |
||
169 | 16 | public function setKeyword($keyword) |
|
170 | { |
||
171 | 16 | $this->keyword = $keyword; |
|
172 | |||
173 | 16 | return $this; |
|
174 | } |
||
175 | |||
176 | /** |
||
177 | * @return string |
||
178 | */ |
||
179 | 5 | public function getLocale() |
|
180 | { |
||
181 | 5 | return $this->locale; |
|
182 | } |
||
183 | |||
184 | /** |
||
185 | * @param string $locale |
||
186 | * |
||
187 | * @return Translation |
||
188 | */ |
||
189 | 14 | public function setLocale($locale) |
|
190 | { |
||
191 | 14 | $this->locale = $locale; |
|
192 | |||
193 | 14 | return $this; |
|
194 | } |
||
195 | |||
196 | /** |
||
197 | * @return string |
||
198 | */ |
||
199 | 1 | public function getFile() |
|
200 | { |
||
201 | 1 | return $this->file; |
|
202 | } |
||
203 | |||
204 | /** |
||
205 | * @param string $file |
||
206 | * |
||
207 | * @return Translation |
||
208 | */ |
||
209 | 6 | public function setFile($file) |
|
210 | { |
||
211 | 6 | $this->file = $file; |
|
212 | |||
213 | 6 | return $this; |
|
214 | } |
||
215 | |||
216 | /** |
||
217 | * @return string |
||
218 | */ |
||
219 | 4 | public function getText() |
|
220 | { |
||
221 | 4 | return $this->text; |
|
222 | } |
||
223 | |||
224 | /** |
||
225 | * @param string $text |
||
226 | * |
||
227 | * @return Translation |
||
228 | */ |
||
229 | 16 | public function setText($text) |
|
230 | { |
||
231 | 16 | $this->text = $text; |
|
232 | |||
233 | 16 | return $this; |
|
234 | } |
||
235 | |||
236 | /** |
||
237 | * @return string |
||
238 | */ |
||
239 | 6 | public function getDomain() |
|
240 | { |
||
241 | 6 | return $this->domain; |
|
242 | } |
||
243 | |||
244 | /** |
||
245 | * @param string $domain |
||
246 | * |
||
247 | * @return Translation |
||
248 | */ |
||
249 | 17 | public function setDomain($domain) |
|
250 | { |
||
251 | 17 | $this->domain = $domain; |
|
252 | |||
253 | 17 | return $this; |
|
254 | } |
||
255 | |||
256 | /** |
||
257 | * @return \DateTime |
||
258 | */ |
||
259 | 1 | public function getCreatedAt() |
|
260 | { |
||
261 | 1 | return $this->createdAt; |
|
262 | } |
||
263 | |||
264 | /** |
||
265 | * @return Translation |
||
266 | */ |
||
267 | 15 | public function setCreatedAt(DateTime $createdAt) |
|
268 | { |
||
269 | 15 | $this->createdAt = $createdAt; |
|
270 | |||
271 | 15 | return $this; |
|
272 | } |
||
273 | |||
274 | /** |
||
275 | * @return \DateTime |
||
276 | */ |
||
277 | 1 | public function getUpdatedAt() |
|
278 | { |
||
279 | 1 | return $this->updatedAt; |
|
280 | } |
||
281 | |||
282 | /** |
||
283 | * @return Translation |
||
284 | */ |
||
285 | 15 | public function setUpdatedAt(DateTime $updatedAt) |
|
286 | { |
||
287 | 15 | $this->updatedAt = $updatedAt; |
|
288 | |||
289 | 15 | return $this; |
|
290 | } |
||
291 | |||
292 | /** |
||
293 | * @return string |
||
294 | */ |
||
295 | 1 | public function getFlag() |
|
296 | { |
||
297 | 1 | return $this->flag; |
|
298 | } |
||
299 | |||
300 | /** |
||
301 | * @param string $flag |
||
302 | * |
||
303 | * @return Translation |
||
304 | */ |
||
305 | 13 | public function setFlag($flag) |
|
306 | { |
||
307 | 13 | $this->flag = $flag; |
|
308 | |||
309 | 13 | return $this; |
|
310 | } |
||
311 | |||
312 | /** |
||
313 | * @param string $translationId |
||
314 | * |
||
315 | * @return Translation |
||
316 | */ |
||
317 | 3 | public function setTranslationId($translationId) |
|
318 | { |
||
319 | 3 | $this->translationId = $translationId; |
|
320 | |||
321 | 3 | return $this; |
|
322 | } |
||
323 | |||
324 | /** |
||
325 | * @return string |
||
326 | */ |
||
327 | 3 | public function getTranslationId() |
|
328 | { |
||
329 | 3 | return $this->translationId; |
|
330 | } |
||
331 | |||
332 | /** |
||
333 | * @return string |
||
334 | */ |
||
335 | 1 | public function getStatus() |
|
336 | { |
||
337 | 1 | return $this->status; |
|
338 | } |
||
339 | |||
340 | /** |
||
341 | * @param string $status |
||
342 | * |
||
343 | * @return Translation |
||
344 | */ |
||
345 | 13 | public function setStatus($status) |
|
346 | { |
||
347 | 13 | $this->status = $status; |
|
348 | |||
349 | 13 | return $this; |
|
350 | } |
||
351 | |||
352 | /** |
||
353 | * @return bool |
||
354 | */ |
||
355 | 1 | public function isDisabled() |
|
356 | { |
||
357 | 1 | return $this->getStatus() === self::STATUS_DISABLED; |
|
358 | } |
||
359 | |||
360 | /** |
||
361 | * @return bool |
||
362 | */ |
||
363 | 1 | public function isDeprecated() |
|
364 | { |
||
365 | 1 | return $this->getStatus() === self::STATUS_DEPRECATED; |
|
366 | } |
||
367 | |||
368 | /** |
||
369 | * @param int $id |
||
0 ignored issues
–
show
|
|||
370 | * |
||
371 | * @return TranslationModel |
||
372 | */ |
||
373 | 1 | public function getTranslationModel($id = null) |
|
374 | { |
||
375 | 1 | $translationModel = new TranslationModel(); |
|
376 | 1 | $translationModel->setKeyword($this->getKeyword()); |
|
377 | 1 | $translationModel->setDomain($this->getDomain()); |
|
378 | 1 | $translationModel->addText($this->getLocale(), $this->getText(), $id); |
|
379 | |||
380 | 1 | return $translationModel; |
|
381 | } |
||
382 | } |
||
383 |
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.