WithRoles   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 12
c 1
b 0
f 0
dl 0
loc 28
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A getAllRolesOnDomain() 0 20 5
1
<?php
2
3
namespace Uccello\Core\Support\Traits;
4
5
use Uccello\Core\Models\Domain;
6
7
trait WithRoles
8
{
9
    /**
10
     * Returns all roles available in a domain
11
     *
12
     * @param \Uccello\Core\Models\Domain $domain
13
     * @return array
14
     */
15
    protected function getAllRolesOnDomain(Domain $domain)
16
    {
17
        // Display ancestors roles only if it is allowed
18
        if (config('uccello.roles.display_ancestors_roles')) {
19
            $treeDomainsIds = $domain->findAncestors()->pluck('id');
20
        } else {
21
            $treeDomainsIds = collect([ $domain->id ]);
22
        }
23
24
        // Get all roles
25
        $roles = [ ];
26
        foreach ($treeDomainsIds as $treeDomainId) {
27
            $_domain = Domain::find($treeDomainId);
28
            foreach ($_domain->roles as $role) {
29
                $roleName = $_domain->id === $domain->id ? $role->name : $_domain->name . ' > ' . $role->name;
30
                $roles[ $role->id ] = $roleName;
31
            }
32
        }
33
34
        return $roles;
35
    }
36
}