7
7
use PhpParser \Node \Stmt \Class_ ;
8
8
use PhpParser \Node \Stmt \ClassLike ;
9
9
use PhpParser \Node \Stmt \Enum_ ;
10
+ use PhpParser \Node \Stmt \EnumCase ;
10
11
use PhpParser \Node \Stmt \Interface_ ;
11
12
use PhpParser \Node \Stmt \Trait_ ;
12
13
use PhpParser \Node \Stmt \TraitUseAdaptation \Alias ;
25
26
* @implements Collector<ClassLike, array{
26
27
* kind: string,
27
28
* name: string,
29
+ * cases: array<string, array{line: int}>,
28
30
* constants: array<string, array{line: int}>,
29
31
* methods: array<string, array{line: int, params: int, abstract: bool, visibility: int-mask-of<Visibility::*>}>,
30
32
* parents: array<string, null>,
@@ -52,6 +54,7 @@ public function getNodeType(): string
52
54
* @return array{
53
55
* kind: string,
54
56
* name: string,
57
+ * cases: array<string, array{line: int}>,
55
58
* constants: array<string, array{line: int}>,
56
59
* methods: array<string, array{line: int, params: int, abstract: bool, visibility: int-mask-of<Visibility::*>}>,
57
60
* parents: array<string, null>,
@@ -73,6 +76,8 @@ public function processNode(
73
76
$ reflection = $ this ->reflectionProvider ->getClass ($ typeName );
74
77
75
78
$ methods = [];
79
+ $ constants = [];
80
+ $ cases = [];
76
81
77
82
foreach ($ node ->getMethods () as $ method ) {
78
83
$ methods [$ method ->name ->toString ()] = [
@@ -83,8 +88,6 @@ public function processNode(
83
88
];
84
89
}
85
90
86
- $ constants = [];
87
-
88
91
foreach ($ node ->getConstants () as $ constant ) {
89
92
foreach ($ constant ->consts as $ const ) {
90
93
$ constants [$ const ->name ->toString ()] = [
@@ -93,10 +96,18 @@ public function processNode(
93
96
}
94
97
}
95
98
99
+ foreach ($ this ->getEnumCases ($ node ) as $ case ) {
100
+ $ cases [$ case ->name ->toString ()] = [
101
+ 'line ' => $ case ->name ->getStartLine (),
102
+ ];
103
+
104
+ }
105
+
96
106
return [
97
107
'kind ' => $ kind ,
98
108
'name ' => $ typeName ,
99
109
'methods ' => $ methods ,
110
+ 'cases ' => $ cases ,
100
111
'constants ' => $ constants ,
101
112
'parents ' => $ this ->getParents ($ reflection ),
102
113
'traits ' => $ this ->getTraits ($ node ),
@@ -182,4 +193,24 @@ private function getKind(ClassLike $node): string
182
193
throw new LogicException ('Unknown class-like node ' );
183
194
}
184
195
196
+ /**
197
+ * @return list<EnumCase>
198
+ */
199
+ private function getEnumCases (ClassLike $ node ): array
200
+ {
201
+ if (!$ node instanceof Enum_) {
202
+ return [];
203
+ }
204
+
205
+ $ result = [];
206
+
207
+ foreach ($ node ->stmts as $ stmt ) {
208
+ if ($ stmt instanceof EnumCase) {
209
+ $ result [] = $ stmt ;
210
+ }
211
+ }
212
+
213
+ return $ result ;
214
+ }
215
+
185
216
}
0 commit comments