Completed
Push — master ( 452c5c...a8b6d8 )
by Ryan
01:53
created

RoleCollection::notAdmin()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 1
eloc 6
nc 1
nop 0
1
<?php namespace Anomaly\UsersModule\Role;
2
3
use Anomaly\Streams\Platform\Entry\EntryCollection;
4
use Anomaly\UsersModule\Role\Contract\RoleInterface;
5
6
/**
7
 * Class RoleCollection
8
 *
9
 * @link          http://anomaly.is/streams-platform
10
 * @author        AnomalyLabs, Inc. <[email protected]>
11
 * @author        Ryan Thompson <[email protected]>
12
 * @package       Anomaly\UsersModule\Role
13
 */
14
class RoleCollection extends EntryCollection
15
{
16
17
    /**
18
     * Return all permissions.
19
     *
20
     * @return array
21
     */
22
    public function permissions()
23
    {
24
        return $this->map(
25
            function (RoleInterface $role) {
26
                return $role->getPermissions();
27
            }
28
        )->flatten()->all();
29
    }
30
31
    /**
32
     * Return if a role as access to a the permission.
33
     *
34
     * @param string $permission
35
     * @return RoleCollection
36
     */
37
    public function hasPermission($permission)
38
    {
39
        return $this->filter(
40
            function (RoleInterface $role) use ($permission) {
41
                return $role->hasPermission($permission);
42
            }
43
        );
44
    }
45
}
46