ExposePermissions   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 30
rs 10
c 1
b 0
f 0
wmc 5
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getCanAttribute() 0 12 4
A getAllPermissionsAttribute() 0 4 1
1
<?php
2
3
namespace Acacha\Users\Traits;
4
5
use Auth;
6
use Spatie\Permission\Models\Permission;
7
8
/**
9
 * Class ExposePermissions.
10
 *
11
 * @package Acacha\Users\Traits
12
 */
13
trait ExposePermissions
14
{
15
    /**
16
     * Get all user permissions in a flat array.
17
     *
18
     * @return array
19
     */
20
    public function getCanAttribute()
21
    {
22
        $permissions = [];
23
        foreach (Permission::all() as $permission) {
24
            if (Auth::check() && Auth::user()->can($permission->name)) {
25
                $permissions[$permission->name] = true;
26
            } else {
27
                $permissions[$permission->name] = false;
28
            }
29
        }
30
        return $permissions;
31
    }
32
33
    /**
34
     * Get all user permissions.
35
     *
36
     * @return \Illuminate\Support\Collection
37
     */
38
    public function getAllPermissionsAttribute()
39
    {
40
        return $this->getAllPermissions();
0 ignored issues
show
Bug introduced by
The method getAllPermissions() does not exist on Acacha\Users\Traits\ExposePermissions. Did you maybe mean getAllPermissionsAttribute()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
41
    }
42
}