Passed
Push — master ( deecf0...b54cbd )
by Luis
03:32
created

AttributesBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 28
ccs 16
cts 16
cp 1
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 48
    public function build(array $classAttributes): array
15
    {
16 48
        $attributes = [];
17 48
        foreach ($classAttributes as $attribute) {
18 39
            if (!($attribute instanceof Property)) {
19 33
                continue;
20
            }
21 33
            $attributes[] = [
22 33
                "\${$attribute->props[0]->name}",
23 33
                $this->resolveVisibility($attribute),
24 33
                $attribute->getDocComment()
25
            ];
26
        }
27 48
        return $attributes;
28
    }
29
30
    /** @param Property $statement */
31 33
    private function resolveVisibility($statement): string
32
    {
33
        switch (true) {
34 33
            case $statement->isPublic():
35 21
                return 'public';
36 33
            case $statement->isPrivate():
37 33
                return 'private';
38
            default:
39 24
                return 'protected';
40
        }
41
    }
42
}
43