Translation   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 45
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setTranslation() 0 20 3
A getTranslation() 0 4 1
1
<?php namespace Rocket\Translation\Model;
2
3
use Carbon\Carbon;
4
use Eloquent;
5
6
/**
7
 * @property integer $id
8
 * @property integer $string_id
9
 * @property integer $language_id
10
 * @property DateTime $date_edition
11
 * @property string $text
12
 */
13
class Translation extends Eloquent
14
{
15
    /**
16
     * @var bool Indicates if the model should be timestamped.
17
     */
18
    public $timestamps = false;
19
20
    /**
21
     * @var string The table associated with the model.
22
     */
23
    protected $table = 'translations';
24
25
    /**
26
     * The attributes that should be mutated to dates.
27
     *
28
     * @var array
29
     */
30
    protected $dates = ['date_edition'];
31
32
    public static function setTranslation($stringId, $languageId, $text)
33
    {
34
        $translation = Translation::where('string_id', $stringId)->where('language_id', $languageId)->first();
35
36
        if (!$translation) {
37
            $translation = new Translation();
38
            $translation->string_id = $stringId;
39
            $translation->language_id = $languageId;
40
        }
41
42
        $translation->text = $text;
43
44
        if ($translation->isDirty()) {
45
            $translation->date_edition = Carbon::now();
46
        }
47
48
        $translation->save();
49
50
        return $translation;
51
    }
52
53
    protected static function getTranslation($stringId, $languageId)
54
    {
55
        return Translation::where('string_id', $stringId)->where('language_id', $languageId)->value('text');
56
    }
57
}
58