Passed
Pull Request — master (#22)
by Luis
24:40 queued 21:48
created

VisibilityFilters   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 22
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3
1
<?php declare(strict_types=1);
2
/**
3
 * PHP version 8.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 PhpParser\Node\Param;
11
use PhpParser\Node\Stmt;
12
use PhpParser\Node\Stmt\ClassConst;
13
use PhpParser\Node\Stmt\ClassMethod;
14
use PhpParser\Node\Stmt\Property;
15
use PhUml\Parser\Code\Builders\Filters\VisibilityFilter;
16
17
/**
18
 * It can run one or more `VisibilityFilter`s.
19
 * Filters will exclude:
20
 *
21
 * - protected members
22
 * - private members
23
 * - both protected and private members if both filters are provided
24
 *
25
 * @see PrivateVisibilityFilter
26
 * @see ProtectedVisibilityFilter
27
 */
28
final class VisibilityFilters
29
{
30
    /** @var VisibilityFilter[] */
31
    private readonly array $filters;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ARRAY, expecting T_VARIABLE on line 31 at column 21
Loading history...
32
33
    /** @param VisibilityFilter[] $filters */
34 56
    public function __construct(array $filters = [])
35
    {
36 56
        $this->filters = $filters;
37
    }
38
39
    /**
40
     * @param Property[]|ClassMethod[]|ClassConst[]|Param[] $definitionMembers
41
     * @return Property[]|ClassMethod[]|ClassConst[]|Param[]
42
     */
43 47
    public function apply(array $definitionMembers): array
44
    {
45 47
        $members = $definitionMembers;
46 47
        foreach ($this->filters as $filter) {
47 14
            $members = array_filter($members, static fn (Stmt|Param $member): bool => $filter->accept($member));
48
        }
49 47
        return $members;
50
    }
51
}
52