UserManagerAbstract   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 36
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A hasPermissions() 0 12 3
A hasPermission() 0 4 1
A getUserPermissions() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Eziat\PermissionBundle\Model;
6
7
/**
8
 * @author Tomas Jakl <[email protected]>
9
 */
10
abstract class UserManagerAbstract implements UserManagerInterface
11
{
12
    /**
13
     * {@inheritdoc}
14
     */
15
    public function hasPermissions(UserPermissionInterface $user, array $permissions) : bool
16
    {
17
        $userPermissions = $this->getPermissions($user);
18
19
        foreach ($permissions as $permission) {
20
            if (!in_array($permission, $userPermissions)) {
21
                return false;
22
            }
23
        }
24
25
        return true;
26
    }
27
28
    /**
29
     * {@inheritdoc}
30
     */
31
    public function hasPermission(UserPermissionInterface $user, $permission) : bool
32
    {
33
        return $this->hasPermissions($user, [$permission]);
34
    }
35
36
    protected function getUserPermissions(UserPermissionInterface $user) : array
37
    {
38
        $permissions = [];
39
        foreach ($user->getPermissions() as $permission) {
40
            $permissions[] = $permission->getName();
41
        }
42
43
        return $permissions;
44
    }
45
}