Failed Conditions
Pull Request — master (#13)
by Adrien
05:33 queued 02:11
created

MultipleRoles::getRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ecodev\Felix\Acl;
6
7
use Exception;
8
use Laminas\Permissions\Acl\Role\RoleInterface;
9
use Stringable;
10
11
/**
12
 * A role containing multiple roles.
13
 */
14
class MultipleRoles implements RoleInterface, Stringable
15
{
16
    /**
17
     * @var string[]
18
     */
19
    private array $roles = [];
20
21
    /**
22
     * @param string[] $roles
23
     */
24 5
    public function __construct(array $roles = [])
25
    {
26 5
        foreach ($roles as $role) {
27 4
            $this->addRole($role);
28
        }
29
    }
30
31
    /**
32
     * Add a role to the list.
33
     */
34 4
    public function addRole(string $role): void
35
    {
36 4
        $this->roles[] = $role;
37
38 4
        $this->roles = array_unique($this->roles);
39 4
        sort($this->roles);
40
    }
41
42 1
    public function getRoleId(): never
1 ignored issue
show
Bug introduced by
The type Ecodev\Felix\Acl\never was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
43
    {
44 1
        throw new Exception('This should never be called. If it is, then it means this class is not used correctly');
45
    }
46
47
    /**
48
     * Return the role list.
49
     *
50
     * @return string[]
51
     */
52 4
    public function getRoles(): array
53
    {
54 4
        return $this->roles;
55
    }
56
57
    /**
58
     * Return whether the given role is included in the list.
59
     */
60 1
    public function has(string $role): bool
61
    {
62 1
        return in_array($role, $this->roles, true);
63
    }
64
65 2
    public function __toString(): string
66
    {
67 2
        return '[' . implode(', ', $this->roles) . ']';
68
    }
69
}
70