Passed
Push — parser-refactoring ( e758c6...b54cbd )
by Luis
11:11
created

AttributesBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 14 3
A resolveVisibility() 0 9 3
1
<?php
2
/**
3
 * PHP version 7.1
4
 *
5
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
6
 */
7
8
namespace PhUml\Parser\Builders;
9
10
use PhpParser\Node\Stmt\Property;
11
12
class AttributesBuilder
13
{
14
    public function build(array $classAttributes): array
15
    {
16
        $attributes = [];
17
        foreach ($classAttributes as $attribute) {
18
            if (!($attribute instanceof Property)) {
19
                continue;
20
            }
21
            $attributes[] = [
22
                "\${$attribute->props[0]->name}",
23
                $this->resolveVisibility($attribute),
24
                $attribute->getDocComment()
25
            ];
26
        }
27
        return $attributes;
28
    }
29
30
    /** @param Property $statement */
31
    private function resolveVisibility($statement): string
32
    {
33
        switch (true) {
34
            case $statement->isPublic():
35
                return 'public';
36
            case $statement->isPrivate():
37
                return 'private';
38
            default:
39
                return 'protected';
40
        }
41
    }
42
}
43