Passed
Pull Request — master (#47)
by
unknown
24:31 queued 09:29
created

Visitor::enterNode()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 12
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 1
Metric Value
cc 5
eloc 6
c 4
b 0
f 1
nc 5
nop 1
dl 0
loc 12
rs 9.6111
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
26
        if ($node->key instanceof String_) {
27
            $this->roles[] = $node->key->value;
28
        }
29
30
        if ($node->value instanceof String_ && !in_array($node->value->value, $this->permissions)) {
31
            $this->permissions[] = $node->value->value;
32
        }
33
    }
34
35
    public function getRoles(): array
36
    {
37
        return $this->roles;
38
    }
39
40
    public function getPermissions(): array
41
    {
42
        return $this->permissions;
43
    }
44
}
45