Completed
Push — master ( 9d1ab7...13f027 )
by Luis
04:13 queued 02:19
created

AttributesBuilder   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A build() 0 13 1
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
use PhUml\Parser\Raw\Builders\Filters\PrivateMembersFilter;
12
use PhUml\Parser\Raw\Builders\Filters\ProtectedMembersFilter;
13
14
/**
15
 * It builds an array with the meta-information of a class attribute
16
 *
17
 * The generated array has the following structure
18
 *
19
 * - name
20
 * - visibility
21
 * - doc block
22
 *
23
 * You can run one or more filters, the current available filters will exclude
24
 *
25
 * - protected attributes
26
 * - private attributes
27
 * - both protected and private if both filters are provided
28
 *
29
 * @see PrivateMembersFilter
30
 * @see ProtectedMembersFilter
31
 */
32
class AttributesBuilder extends MembersBuilder
33
{
34
    public function build(array $classAttributes): array
35
    {
36 78
        $attributes = array_filter($classAttributes, function ($attribute) {
37 69
            return $attribute instanceof Property;
38 78
        });
39
40 78
        return array_map(function (Property $attribute) {
41
            return [
42 60
                "\${$attribute->props[0]->name}",
43 60
                $this->resolveVisibility($attribute),
44 60
                $attribute->getDocComment()
45
            ];
46 78
        }, $this->runFilters($attributes));
47
    }
48
}
49