Passed
Pull Request — master (#39)
by Arjay
15:07 queued 05:40
created

HasRoleAndPermission::getPermissions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
namespace Yajra\Acl\Traits;
4
5
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
6
use Yajra\Acl\Models\Permission;
7
8
trait HasRoleAndPermission
9
{
10
    use HasRole {
11
        HasRole::getPermissions as getRolePermissions;
12
    }
13
14
    use InteractsWithPermission;
15
16
    /**
17
     * Get all user permissions slug.
18
     *
19
     * @return array|null
20
     */
21
    public function getPermissions(): array
22
    {
23
        $rolePermissions = $this->getRolePermissions();
24
        $userPermissions = $this->permissions->pluck('slug')->toArray();
25
26
        return collect($userPermissions)->merge($rolePermissions)->unique()->toArray();
27
    }
28
}
29