Completed
Push — master ( b739db...92d607 )
by Abdelrahman
02:42
created

RolePolicy::remove()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 6
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
/*
4
 * NOTICE OF LICENSE
5
 *
6
 * Part of the Rinvex Fort Package.
7
 *
8
 * This source file is subject to The MIT License (MIT)
9
 * that is bundled with this package in the LICENSE file.
10
 *
11
 * Package: Rinvex Fort Package
12
 * License: The MIT License (MIT)
13
 * Link:    https://rinvex.com
14
 */
15
16
namespace Rinvex\Fort\Policies;
17
18
use Rinvex\Fort\Models\Role;
19
use Rinvex\Fort\Models\User;
20
use Illuminate\Auth\Access\HandlesAuthorization;
21
22
class RolePolicy
23
{
24
    use HandlesAuthorization;
25
26
    /**
27
     * Determine whether the user can view the role.
28
     *
29
     * @param \Rinvex\Fort\Models\User $user
30
     * @param \Rinvex\Fort\Models\Role $role
31
     *
32
     * @return bool
33
     */
34
    public function view(User $user, Role $role)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $role is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
35
    {
36
        return true;
37
    }
38
39
    /**
40
     * Determine whether the user can create roles.
41
     *
42
     * @param \Rinvex\Fort\Models\User $user
43
     *
44
     * @return bool
45
     */
46
    public function create(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
47
    {
48
        return true;
49
    }
50
51
    /**
52
     * Determine whether the user can update the role.
53
     *
54
     * @param \Rinvex\Fort\Models\User $user
55
     * @param \Rinvex\Fort\Models\Role $role
56
     *
57
     * @return bool
58
     */
59
    public function update(User $user, Role $role)
60
    {
61
        // Super admin & protected roles can be controlled by super admins only!
62
        return $role->isProtected() || ($role->isSuperadmin() && ! $user->isSuperadmin()) ? false : true;
63
    }
64
65
    /**
66
     * Determine whether the user can delete the role.
67
     *
68
     * @param \Rinvex\Fort\Models\User $user
69
     * @param \Rinvex\Fort\Models\Role $role
70
     *
71
     * @return bool
72
     */
73
    public function delete(User $user, Role $role)
74
    {
75
        // Super admin & protected roles can be controlled by super admins only! Deleted role must have no abilities or users attached!!
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 136 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
76
        return $role->isProtected() || ($role->isSuperadmin() && ! $user->isSuperadmin()) || ! $role->abilities->isEmpty() || ! $role->users->isEmpty() ? false : true;
0 ignored issues
show
Documentation introduced by
The property abilities does not exist on object<Rinvex\Fort\Models\Role>. 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...
Documentation introduced by
The property users does not exist on object<Rinvex\Fort\Models\Role>. 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...
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 167 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
77
    }
78
79
    /**
80
     * Determine whether the user can import the roles.
81
     *
82
     * @param \Rinvex\Fort\Models\User $user
83
     *
84
     * @return bool
85
     */
86
    public function import(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
87
    {
88
        return true;
89
    }
90
91
    /**
92
     * Determine whether the user can export the roles.
93
     *
94
     * @param \Rinvex\Fort\Models\User $user
95
     *
96
     * @return bool
97
     */
98
    public function export(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
99
    {
100
        return true;
101
    }
102
103
    /**
104
     * Determine whether the user can give the role.
105
     *
106
     * @param \Rinvex\Fort\Models\User $user
107
     *
108
     * @return bool
109
     */
110
    public function give(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
111
    {
112
        // Regardless of this ability, admins must have
113
        // the given roles before giving it to others.
114
        return true;
115
    }
116
117
    /**
118
     * Determine whether the user can remove the role.
119
     *
120
     * @param \Rinvex\Fort\Models\User $user
121
     *
122
     * @return bool
123
     */
124
    public function remove(User $user)
0 ignored issues
show
Unused Code introduced by
The parameter $user is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
125
    {
126
        // Regardless of this ability, admins must have
127
        // the removed roles before removing it from others.
128
        return true;
129
    }
130
}
131