Completed
Pull Request — master (#2)
by ARCANEDEV
03:07
created

PermissionsGroup   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getHashedIdAttribute() 0 4 1
A firstHashedOrFail() 0 6 1
1
<?php namespace Arcanesoft\Auth\Models;
2
3
use \Arcanedev\LaravelAuth\Models\PermissionsGroup as BasePermissionsGroupModel;
4
5
/**
6
 * Class     PermissionsGroup
7
 *
8
 * @package  Arcanesoft\Auth\Models
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @property  string  hashed_id
12
 */
13
class PermissionsGroup extends BasePermissionsGroupModel
14
{
15
    /* ------------------------------------------------------------------------------------------------
16
     |  Getters & Setters
17
     | ------------------------------------------------------------------------------------------------
18
     */
19
    /**
20
     * Get the permissions group hash id.
21
     *
22
     * @return string
23
     */
24
    public function getHashedIdAttribute()
25
    {
26
        return hasher()->encode($this->id);
27
    }
28
29
    /* ------------------------------------------------------------------------------------------------
30
     |  Main Function
31
     | ------------------------------------------------------------------------------------------------
32
     */
33
    /**
34
     * Get a permission from a hashed id or fail if not found.
35
     *
36
     * @param  string  $hashedId
37
     *
38
     * @return self
39
     *
40
     * @throws \Illuminate\Database\Eloquent\ModelNotFoundException
41
     */
42
    public static function firstHashedOrFail($hashedId)
43
    {
44
        $id = head(hasher()->decode($hashedId));
45
46
        return self::where('id', $id)->firstOrFail();
47
    }
48
}
49