Permission   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 74
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getLevel() 0 3 1
A scopeOfScope() 0 3 1
A grantable() 0 3 1
1
<?php
2
3
namespace Mrluke\Privileges\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
7
use Mrluke\Privileges\Contracts\Permission as Contract;
8
9
/**
10
 * Permission model for package.
11
 *
12
 * @author    Łukasz Sitnicki (mr-luke)
13
 * @link      http://github.com/mr-luke/privileges
14
 *
15
 * @category  Laravel
16
 * @package   mr-luke/privileges
17
 * @license   MIT
18
 */
19
class Permission extends Model implements Contract
20
{
21
    /**
22
     * The attributes that should be cast to native types.
23
     *
24
     * @var array
25
     */
26
    protected $casts = [
27
        'level'  => 'integer',
28
    ];
29
30
    /**
31
     * The event map for the model.
32
     *
33
     * @var array
34
     */
35
    protected $dispatchesEvents = [
36
        'created'  => \Mrluke\Privileges\Events\Permission\Created::class,
37
        'creating' => \Mrluke\Privileges\Events\Permission\Creating::class,
38
        'deleted'  => \Mrluke\Privileges\Events\Permission\Deleted::class,
39
        'deleting' => \Mrluke\Privileges\Events\Permission\Deleting::class,
40
        'updated'  => \Mrluke\Privileges\Events\Permission\Updated::class,
41
        'updating' => \Mrluke\Privileges\Events\Permission\Updating::class,
42
    ];
43
44
    /**
45
     * The attributes that are mass assignable.
46
     *
47
     * @var array
48
     */
49
    protected $fillable = ['scope', 'level'];
50
51
    /**
52
     * The table associated with the model.
53
     *
54
     * @var string
55
     */
56
    protected $table = 'priv_permissions';
57
58
    /**
59
     * Indicates if the model should be timestamped.
60
     *
61
     * @var bool
62
     */
63
    public $timestamps = false;
64
65
    /**
66
     * Return related model.
67
     */
68
    public function grantable()
69
    {
70
        return $this->morphTo();
71
    }
72
73
    /**
74
     * Scope a query to only include specific scope.
75
     *
76
     * @param  \Illuminate\Database\Eloquent\Builder $query
77
     * @param  string                                $scope
78
     * @return \Illuminate\Database\Eloquent\Builder
79
     */
80
    public function scopeOfScope($query, string $scope)
81
    {
82
        return $query->where('scope', $scope);
83
    }
84
85
    /**
86
     * Return permission level.
87
     *
88
     * @return int
89
     */
90
    public function getLevel():int
91
    {
92
        return $this->level;
93
    }
94
}
95