Visitor   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 14
c 1
b 0
f 1
dl 0
loc 36
rs 10
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getRoles() 0 3 1
A getPermissions() 0 3 1
A enterNode() 0 16 6
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 (
31
            $node->value instanceof String_
32
            && !in_array($node->value->value, $this->permissions)
33
            && !strstr($node->value->value, 'role:')
34
        ) {
35
            $this->permissions[] = $node->value->value;
36
        }
37
    }
38
39
    public function getRoles(): array
40
    {
41
        return $this->roles;
42
    }
43
44
    public function getPermissions(): array
45
    {
46
        return $this->permissions;
47
    }
48
}
49