TagGroup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 33
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A tags() 0 5 1
A __construct() 0 5 1
A setNameAttribute() 0 4 1
1
<?php namespace Conner\Tagging\Model;
2
3
use Conner\Tagging\TaggingUtility;
4
use Illuminate\Database\Eloquent\Model;
5
use Illuminate\Support\Collection;
6
7
/**
8
 * @package Conner\Tagging\Model
9
 *
10
 * @property string id
11
 * @property string slug
12
 * @property string name
13
 * @property-read Collection|Tag[] tags
14
 */
15
class TagGroup extends Model
16
{
17
    protected $table = 'tagging_tag_groups';
18
    public $timestamps = false;
19
    protected $fillable = ['name'];
20
21
    /**
22
     * @param array $attributes
23
     */
24
    public function __construct(array $attributes = [])
25
    {
26
        parent::__construct($attributes);
27
28
        $this->connection = config('tagging.connection');
29
    }
30
31
    /**
32
     * Get suggested tags
33
     */
34
    public function tags()
35
    {
36
        $model = TaggingUtility::tagModelString();
37
38
        return $this->hasMany($model, 'tag_group_id');
39
    }
40
41
    /**
42
     * @param $value
43
     */
44
    public function setNameAttribute($value)
45
    {
46
        $this->attributes['name'] = $value;
47
        $this->attributes['slug'] = TaggingUtility::normalize($value);
48
    }
49
}
50