TagGroup   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

3 Methods

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