Completed
Pull Request — master (#2775)
by Jeroen
10:25
created

Translation::getFlag()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
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 View Code Duplication
    public function prePersist()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
116
    {
117
        $this->createdAt = new DateTime();
118
        $this->updatedAt = new DateTime();
119
        $this->flag = self::FLAG_NEW;
120
121
        return $this->id;
122
    }
123
124
    /**
125
     * @ORM\PreUpdate
126
     */
127 3 View Code Duplication
    public function preUpdate()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
128
    {
129 3
        $this->updatedAt = new DateTime();
130
131 3
        if ($this->flag === null) {
132 3
            $this->flag = self::FLAG_UPDATED;
133
        }
134 3
    }
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 3
    public function getKeyword()
160
    {
161 3
        return $this->keyword;
162
    }
163
164
    /**
165
     * @param string $keyword
166
     *
167
     * @return Translation
168
     */
169 4
    public function setKeyword($keyword)
170
    {
171 4
        $this->keyword = $keyword;
172
173 4
        return $this;
174
    }
175
176
    /**
177
     * @return string
178
     */
179 2
    public function getLocale()
180
    {
181 2
        return $this->locale;
182
    }
183
184
    /**
185
     * @param string $locale
186
     *
187
     * @return Translation
188
     */
189 2
    public function setLocale($locale)
190
    {
191 2
        $this->locale = $locale;
192
193 2
        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 3
    public function setFile($file)
210
    {
211 3
        $this->file = $file;
212
213 3
        return $this;
214
    }
215
216
    /**
217
     * @return string
218
     */
219 3
    public function getText()
220
    {
221 3
        return $this->text;
222
    }
223
224
    /**
225
     * @param string $text
226
     *
227
     * @return Translation
228
     */
229 4
    public function setText($text)
230
    {
231 4
        $this->text = $text;
232
233 4
        return $this;
234
    }
235
236
    /**
237
     * @return string
238
     */
239 3
    public function getDomain()
240
    {
241 3
        return $this->domain;
242
    }
243
244
    /**
245
     * @param string $domain
246
     *
247
     * @return Translation
248
     */
249 5
    public function setDomain($domain)
250
    {
251 5
        $this->domain = $domain;
252
253 5
        return $this;
254
    }
255
256
    /**
257
     * @return \DateTime
258
     */
259 1
    public function getCreatedAt()
260
    {
261 1
        return $this->createdAt;
262
    }
263
264
    /**
265
     * @param \DateTime $createdAt
266
     *
267
     * @return Translation
268
     */
269 3
    public function setCreatedAt(DateTime $createdAt)
270
    {
271 3
        $this->createdAt = $createdAt;
272
273 3
        return $this;
274
    }
275
276
    /**
277
     * @return \DateTime
278
     */
279 1
    public function getUpdatedAt()
280
    {
281 1
        return $this->updatedAt;
282
    }
283
284
    /**
285
     * @param DateTime $updatedAt
286
     *
287
     * @return Translation
288
     */
289 3
    public function setUpdatedAt(DateTime $updatedAt)
290
    {
291 3
        $this->updatedAt = $updatedAt;
292
293 3
        return $this;
294
    }
295
296
    /**
297
     * @return string
298
     */
299 1
    public function getFlag()
300
    {
301 1
        return $this->flag;
302
    }
303
304
    /**
305
     * @param string $flag
306
     *
307
     * @return Translation
308
     */
309 1
    public function setFlag($flag)
310
    {
311 1
        $this->flag = $flag;
312
313 1
        return $this;
314
    }
315
316
    /**
317
     * @param string $translationId
318
     *
319
     * @return Translation
320
     */
321
    public function setTranslationId($translationId)
322
    {
323
        $this->translationId = $translationId;
324
325
        return $this;
326
    }
327
328
    /**
329
     * @return string
330
     */
331
    public function getTranslationId()
332
    {
333
        return $this->translationId;
334
    }
335
336
    /**
337
     * @return string
338
     */
339 1
    public function getStatus()
340
    {
341 1
        return $this->status;
342
    }
343
344
    /**
345
     * @param string $status
346
     *
347
     * @return Translation
348
     */
349 1
    public function setStatus($status)
350
    {
351 1
        $this->status = $status;
352
353 1
        return $this;
354
    }
355
356
    /**
357
     * @return bool
358
     */
359 1
    public function isDisabled()
360
    {
361 1
        return $this->getStatus() === self::STATUS_DISABLED;
362
    }
363
364
    /**
365
     * @return bool
366
     */
367 1
    public function isDeprecated()
368
    {
369 1
        return $this->getStatus() === self::STATUS_DEPRECATED;
370
    }
371
372
    /**
373
     * @param int $id
0 ignored issues
show
Documentation introduced by
Should the type for parameter $id not be integer|null?

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.

Loading history...
374
     *
375
     * @return TranslationModel
376
     */
377 1
    public function getTranslationModel($id = null)
378
    {
379 1
        $translationModel = new TranslationModel();
380 1
        $translationModel->setKeyword($this->getKeyword());
381 1
        $translationModel->setDomain($this->getDomain());
382 1
        $translationModel->addText($this->getLocale(), $this->getText(), $id);
383
384 1
        return $translationModel;
385
    }
386
}
387