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

AttributesBuilder::resolveVisibility()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 9
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 3
nop 1
dl 0
loc 9
ccs 6
cts 6
cp 1
crap 3
rs 9.6666
c 0
b 0
f 0
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