Passed
Push — cleanup ( 1df3c6...d09870 )
by Luis
12:15
created

AttributesBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A build() 0 10 1
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\Raw\Builders;
9
10
use PhpParser\Node\Stmt\Property;
11
12
/**
13
 * It builds an array with the meta-information of a class attribute
14
 *
15
 * The generated array has the following structure
16
 *
17
 * - name
18
 * - visibility
19
 * - doc block
20
 */
21
class AttributesBuilder
22
{
23
    public function build(array $classAttributes): array
24
    {
25
        return array_map(function (Property $attribute) {
26
            return [
27
                "\${$attribute->props[0]->name}",
28
                $this->resolveVisibility($attribute),
29
                $attribute->getDocComment()
30
            ];
31
        }, array_filter($classAttributes, function ($attribute) {
32
            return $attribute instanceof Property;
33
        }));
34
    }
35
36
    private function resolveVisibility(Property $attribute): string
37
    {
38
        switch (true) {
39
            case $attribute->isPublic():
40
                return 'public';
41
            case $attribute->isPrivate():
42
                return 'private';
43
            default:
44
                return 'protected';
45
        }
46
    }
47
}
48