TermData   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 72
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0
wmc 6
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 2
A term() 0 4 1
A save() 0 10 2
A toArray() 0 6 1
1
<?php
2
3
/**
4
 * This model represents one translation for a term.
5
 */
6
namespace Rocket\Taxonomy\Model;
7
8
use Illuminate\Database\Eloquent\Model;
9
use Rocket\Taxonomy\Support\Laravel5\Facade as T;
10
11
/**
12
 * The translation Data for a term
13
 *
14
 * @property int $id
15
 * @property int $term_id
16
 * @property int $language_id
17
 * @property string $title
18
 * @property string $description
19
 */
20
class TermData extends Model
21
{
22
    /**
23
     * @var bool Indicates if the model should be timestamped.
24
     */
25
    public $timestamps = false;
26
27
    /**
28
     * @var string The table associated with the model.
29
     */
30
    protected $table = 'taxonomy_terms_data';
31
32
    /**
33
     * When used in a term, we set this to true or false
34
     */
35
    public $translated = true;
36
37
    /**
38
     * @var array The attributes that are mass assignable.
39
     */
40
    protected $fillable = ['term_id', 'language_id', 'title', 'description'];
41
42
    /**
43
     * Create a new Eloquent model instance.
44
     *
45
     * @param  array  $attributes
46
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
47
     */
48
    public function __construct(array $attributes = [])
49
    {
50
        parent::__construct($attributes);
51
52
        if (array_key_exists('translated', $attributes)) {
53
            $this->translated = $attributes['translated'];
54
        }
55
    }
56
57
    /**
58
     * Get the term this data is linked to.
59 174
     *
60
     * @codeCoverageIgnore
61 174
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
62 3
     */
63 3
    public function term()
64
    {
65 174
        return $this->belongsTo(TermContainer::class, 'term_id');
66
    }
67 174
68 174
    /**
69
     * Save the model to the database.
70
     *
71
     * @param  array  $options
72
     * @return bool
73
     */
74
    public function save(array $options = [])
75
    {
76
        if ($this->translated === false) {
77
            $this->translated = true;
78
        }
79
80
        T::uncacheTerm($this->term_id);
81
82
        parent::save($options);
83
    }
84
85
    public function toArray()
86
    {
87
        $array = parent::toArray();
88
        $array['translated'] = $this->translated;
89
        return $array;
90
    }
91
}
92