Passed
Push — 1.6 ( c2a002 )
by Luis
05:37
created

FiltersRunner::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\Code\Builders\Members;
9
10
use PhUml\Parser\Code\Builders\Filters\VisibilityFilter;
11
12
/**
13
 * It can run one or more `VisibilityFilter`s.
14
 * Filters will exclude:
15
 *
16
 * - protected members
17
 * - private members
18
 * - both protected and private members if both filters are provided
19
 *
20
 * @see PrivateVisibilityFilter
21
 * @see ProtectedVisibilityFilter
22
 */
23
class FiltersRunner
24
{
25
    /** @var VisibilityFilter[] */
26
    protected $filters;
27
28
    /** @param VisibilityFilter */
29 165
    public function __construct(array $filters = [])
30
    {
31 165
        $this->filters = $filters;
32 165
    }
33
34
    /**
35
     * @param \PhpParser\Node\Stmt\Property[]|\PhpParser\Node\Stmt\ClassMethod $classMembers
36
     * @return \PhpParser\Node\Stmt\Property[]|\PhpParser\Node\Stmt\ClassMethod
37
     */
38 129
    protected function runFilters(array $classMembers): array
39
    {
40 129
        $attributes = $classMembers;
41 129
        foreach ($this->filters as $filter) {
42 33
            $attributes = array_filter($attributes, [$filter, 'accept']);
43
        }
44 129
        return $attributes;
45
    }
46
47
    /** @param \PhpParser\Node\Stmt\Property|\PhpParser\Node\Stmt\ClassMethod $member */
48 105
    protected function resolveVisibility($member): string
49
    {
50
        switch (true) {
51 105
            case $member->isPublic():
52 102
                return 'public';
53 84
            case $member->isPrivate():
54 75
                return 'private';
55
            default:
56 72
                return 'protected';
57
        }
58
    }
59
}
60