1: | <?php declare(strict_types = 1); |
2: | |
3: | namespace ApiGen\Analyzer; |
4: | |
5: | use ApiGen\Info\ClassLikeInfo; |
6: | use ApiGen\Info\FunctionInfo; |
7: | use ApiGen\Info\MemberInfo; |
8: | use PhpParser\Node; |
9: | use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagValueNode; |
10: | |
11: | |
12: | class Filter |
13: | { |
14: | |
15: | protected int $excludedVisibilityMask = 0; |
16: | |
17: | |
18: | |
19: | |
20: | |
21: | public function __construct( |
22: | bool $excludeProtected, |
23: | bool $excludePrivate, |
24: | protected array $excludeTagged, |
25: | ) { |
26: | $this->excludedVisibilityMask |= ($excludeProtected ? Node\Stmt\Class_::MODIFIER_PROTECTED : 0); |
27: | $this->excludedVisibilityMask |= ($excludePrivate ? Node\Stmt\Class_::MODIFIER_PRIVATE : 0); |
28: | } |
29: | |
30: | |
31: | public function filterClassLikeNode(Node\Stmt\ClassLike $node): bool |
32: | { |
33: | return true; |
34: | } |
35: | |
36: | |
37: | |
38: | |
39: | |
40: | public function filterClassLikeTags(array $tags): bool |
41: | { |
42: | foreach ($this->excludeTagged as $tag) { |
43: | if (isset($tags[$tag])) { |
44: | return false; |
45: | } |
46: | } |
47: | |
48: | return true; |
49: | } |
50: | |
51: | |
52: | public function filterClassLikeInfo(ClassLikeInfo $info): bool |
53: | { |
54: | return true; |
55: | } |
56: | |
57: | |
58: | public function filterFunctionNode(Node\Stmt\Function_ $node): bool |
59: | { |
60: | return true; |
61: | } |
62: | |
63: | |
64: | |
65: | |
66: | |
67: | public function filterFunctionTags(array $tags): bool |
68: | { |
69: | foreach ($this->excludeTagged as $tag) { |
70: | if (isset($tags[$tag])) { |
71: | return false; |
72: | } |
73: | } |
74: | |
75: | return true; |
76: | } |
77: | |
78: | |
79: | public function filterFunctionInfo(FunctionInfo $info): bool |
80: | { |
81: | return true; |
82: | } |
83: | |
84: | |
85: | public function filterConstantNode(Node\Stmt\ClassConst $node): bool |
86: | { |
87: | return ($node->flags & $this->excludedVisibilityMask) === 0; |
88: | } |
89: | |
90: | |
91: | public function filterPropertyNode(Node\Stmt\Property $node): bool |
92: | { |
93: | return ($node->flags & $this->excludedVisibilityMask) === 0; |
94: | } |
95: | |
96: | |
97: | public function filterPromotedPropertyNode(Node\Param $node): bool |
98: | { |
99: | return ($node->flags & $this->excludedVisibilityMask) === 0; |
100: | } |
101: | |
102: | |
103: | public function filterMethodNode(Node\Stmt\ClassMethod $node): bool |
104: | { |
105: | return ($node->flags & $this->excludedVisibilityMask) === 0; |
106: | } |
107: | |
108: | |
109: | public function filterEnumCaseNode(Node\Stmt\EnumCase $node): bool |
110: | { |
111: | return true; |
112: | } |
113: | |
114: | |
115: | |
116: | |
117: | |
118: | public function filterMemberTags(array $tags): bool |
119: | { |
120: | foreach ($this->excludeTagged as $tag) { |
121: | if (isset($tags[$tag])) { |
122: | return false; |
123: | } |
124: | } |
125: | |
126: | return true; |
127: | } |
128: | |
129: | |
130: | public function filterMemberInfo(ClassLikeInfo $classLike, MemberInfo $member): bool |
131: | { |
132: | return true; |
133: | } |
134: | } |
135: | |