ExposePermissions::getAllPermissionsAttribute()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

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