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

Permission   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getHashedIdAttribute() 0 4 1
A firstHashedOrFail() 0 6 1
A getIds() 0 4 1
A hasGroup() 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 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 = head(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;
0 ignored issues
show
Documentation introduced by
The property group_id does not exist on object<Arcanesoft\Auth\Models\Permission>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
69
    }
70
}
71