Completed
Pull Request — master (#1)
by ARCANEDEV
04:05
created

Permission   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 13
Bugs 0 Features 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 63
rs 10
c 13
b 0
f 0
ccs 9
cts 9
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A group() 0 4 1
A setSlugAttribute() 0 4 1
1
<?php namespace Arcanedev\LaravelAuth\Models;
2
3
use Arcanedev\LaravelAuth\Bases\Model;
4
use Arcanedev\LaravelAuth\Traits\AuthPermissionRelationships;
5
use Arcanedev\LaravelAuth\Traits\AuthRoleTrait;
6
use Arcanedev\LaravelAuth\Traits\Slugable;
7
use Arcanesoft\Contracts\Auth\Models\Permission as PermissionContract;
8
9
/**
10
 * Class     Permission
11
 *
12
 * @package  Arcanedev\LaravelAuth\Models
13
 * @author   ARCANEDEV <[email protected]>
14
 *
15
 * @property  int                                            id
16
 * @property  int                                            group_id
17
 * @property  string                                         name
18
 * @property  string                                         slug
19
 * @property  string                                         description
20
 * @property  \Carbon\Carbon                                 created_at
21
 * @property  \Carbon\Carbon                                 updated_at
22
 * @property  \Illuminate\Database\Eloquent\Collection       roles
23
 * @property  \Arcanedev\LaravelAuth\Models\PermissionsGroup group
24
 */
25
class Permission extends Model implements PermissionContract
26
{
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Traits
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    use AuthPermissionRelationships, AuthRoleTrait, Slugable;
32
33
    /* ------------------------------------------------------------------------------------------------
34
     |  Properties
35
     | ------------------------------------------------------------------------------------------------
36
     */
37
    /**
38
     * The attributes that are mass assignable.
39
     *
40
     * @var array
41
     */
42
    protected $fillable = ['group_id', 'name', 'slug', 'description'];
43
44
    /* ------------------------------------------------------------------------------------------------
45
     |  Constructor
46
     | ------------------------------------------------------------------------------------------------
47
     */
48
    /**
49
     * Create a new Eloquent model instance.
50
     *
51
     * @param  array  $attributes
52
     */
53 240
    public function __construct(array $attributes = [])
54
    {
55 240
        $this->setTable(config('laravel-auth.permissions.table', 'permissions'));
56
57 240
        parent::__construct($attributes);
58 240
    }
59
60
    /* ------------------------------------------------------------------------------------------------
61
     |  Relationships
62
     | ------------------------------------------------------------------------------------------------
63
     */
64
    /**
65
     * Permission belongs to one group.
66
     *
67
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
68
     */
69 4
    public function group()
70
    {
71 4
        return $this->belongsTo(PermissionsGroup::class, 'group_id');
72
    }
73
74
    /* ------------------------------------------------------------------------------------------------
75
     |  Setters & Getters
76
     | ------------------------------------------------------------------------------------------------
77
     */
78
    /**
79
     * Set the slug attribute.
80
     *
81
     * @param  string  $slug
82
     */
83 100
    public function setSlugAttribute($slug)
84
    {
85 100
        $this->attributes['slug'] = $this->slugify($slug);
86 100
    }
87
}
88