Passed
Pull Request — master (#47)
by
unknown
15:39 queued 42s
created

Visitor::getRoles()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace hipanel\rbac\console\converter;
5
6
use PhpParser\Node\Expr\ArrayItem;
7
use PhpParser\Node\Scalar\String_;
8
use PhpParser\NodeVisitorAbstract;
9
use PhpParser\Node;
10
11
class Visitor extends NodeVisitorAbstract
12
{
13
    /** @var string[]  */
14
    private array $roles = [];
15
16
    /** @var string[]  */
17
    private array $permissions = [];
18
19
    /** @inerhitDoc */
20
    public function enterNode(Node $node)
21
    {
22
        if (!$node instanceof ArrayItem) {
23
            return;
24
        }
25
        if ($node->key instanceof String_) {
26
            $this->roles[] = $node->key->value;
27
        }
28
29
        if ($node->value instanceof String_ && !in_array($node->value->value, $this->permissions)) {
30
            $this->permissions[] = $node->value->value;
31
        }
32
    }
33
34
    public function getRoles(): array
35
    {
36
        return $this->roles;
37
    }
38
39
    public function getPermissions(): array
40
    {
41
        return $this->permissions;
42
    }
43
}
44