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

Permission::hasGroup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 0
crap 2
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