Code Duplication    Length = 27-30 lines in 2 locations

src/Traits/EntrustUserTrait.php 2 locations

@@ 102-128 (lines=27) @@
99
     *
100
     * @return bool
101
     */
102
    public function hasRole($name, $requireAll = false)
103
    {
104
        if (is_array($name)) {
105
            foreach ($name as $roleName) {
106
                $hasRole = $this->hasRole($roleName);
107
108
                if ($hasRole && !$requireAll) {
109
                    return true;
110
                } elseif (!$hasRole && $requireAll) {
111
                    return false;
112
                }
113
            }
114
115
            // If we've made it this far and $requireAll is FALSE, then NONE of the roles were found
116
            // If we've made it this far and $requireAll is TRUE, then ALL of the roles were found.
117
            // Return the value of $requireAll;
118
            return $requireAll;
119
        } else {
120
            foreach ($this->cachedRoles() as $role) {
121
                if ($role->name == $name) {
122
                    return true;
123
                }
124
            }
125
        }
126
127
        return false;
128
    }
129
130
    /**
131
     * Check if user has a permission by its name.
@@ 140-169 (lines=30) @@
137
     *
138
     * @return bool
139
     */
140
    public function can($permission, $requireAll = false)
141
    {
142
        if (is_array($permission)) {
143
            foreach ($permission as $permName) {
144
                $hasPerm = $this->can($permName);
145
146
                if ($hasPerm && !$requireAll) {
147
                    return true;
148
                } elseif (!$hasPerm && $requireAll) {
149
                    return false;
150
                }
151
            }
152
153
            // If we've made it this far and $requireAll is FALSE, then NONE of the perms were found
154
            // If we've made it this far and $requireAll is TRUE, then ALL of the perms were found.
155
            // Return the value of $requireAll;
156
            return $requireAll;
157
        } else {
158
            foreach ($this->cachedRoles() as $role) {
159
                // Validate against the Permission table
160
                foreach ($role->cachedPermissions() as $perm) {
161
                    if (str_is($permission, $perm->name)) {
162
                        return true;
163
                    }
164
                }
165
            }
166
        }
167
168
        return false;
169
    }
170
171
    /**
172
     * Checks role(s) and permission(s).