Completed
Push — master ( 8da79d...fd43b2 )
by ARCANEDEV
03:03
created

Permission   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 5
c 4
b 0
f 0
lcom 2
cbo 2
dl 0
loc 74
ccs 0
cts 9
cp 0
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getHashedIdAttribute() 0 4 1
A getIds() 0 4 1
A hasGroup() 0 4 1
A firstHashedOrFail() 0 6 1
A hasher() 0 4 1
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use Arcanedev\LaravelAuth\Models\Permission as BasePermissionModel;
4
5
/**
6
 * Class     Permission
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 */
11
class Permission extends BasePermissionModel
12
{
13
    /* ------------------------------------------------------------------------------------------------
14
     |  Getters & Setters
15
     | ------------------------------------------------------------------------------------------------
16
     */
17
    /**
18
     * Get the role hash id.
19
     *
20
     * @return string
21
     */
22
    public function getHashedIdAttribute()
23
    {
24
        return self::hasher()->encode($this->id);
25
    }
26
27
    /* ------------------------------------------------------------------------------------------------
28
     |  Main Function
29
     | ------------------------------------------------------------------------------------------------
30
     */
31
    /**
32
     * Get a permission from a hashed id or fail if not found.
33
     *
34
     * @param  string  $hashedId
35
     *
36
     * @return self
37
     *
38
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
39
     */
40
    public static function firstHashedOrFail($hashedId)
41
    {
42
        $id = self::hasher()->decode($hashedId);
43
44
        return self::where('id', $id)->firstOrFail();
45
    }
46
47
    /**
48
     * Get the ids of all permissions.
49
     *
50
     * @return \Illuminate\Database\Eloquent\Collection
51
     */
52
    public static function getIds()
53
    {
54
        return self::orderBy('id')->lists('id');
55
    }
56
57
    /* ------------------------------------------------------------------------------------------------
58
     |  Check Functions
59
     | ------------------------------------------------------------------------------------------------
60
     */
61
    /**
62
     * Check if permission has a group.
63
     *
64
     * @return bool
65
     */
66
    public function hasGroup()
67
    {
68
        return $this->group_id !== 0;
69
    }
70
71
    /* ------------------------------------------------------------------------------------------------
72
     |  Other Functions
73
     | ------------------------------------------------------------------------------------------------
74
     */
75
    /**
76
     * Get the hasher.
77
     *
78
     * @return \Arcanedev\Hasher\Contracts\HashManager
79
     */
80
    protected static function hasher()
81
    {
82
        return hasher();
83
    }
84
}
85