File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed
Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -121,11 +121,39 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
121121 continue ;
122122 }
123123
124+ // Skip anonymous classes (preceded by 'new' keyword)
125+ if ($ token ->isGivenKind (T_CLASS ) && $ this ->isAnonymousClass ($ tokens , $ index )) {
126+ continue ;
127+ }
128+
124129 $ structureName = $ this ->getStructureName ($ tokens , $ index );
125130 $ this ->processStructureDocBlock ($ tokens , $ index , $ annotations , $ structureName );
126131 }
127132 }
128133
134+ private function isAnonymousClass (Tokens $ tokens , int $ classIndex ): bool
135+ {
136+ // Look backwards for 'new' keyword
137+ for ($ i = $ classIndex - 1 ; $ i >= 0 ; --$ i ) {
138+ $ token = $ tokens [$ i ];
139+
140+ // Skip whitespace and attributes
141+ if ($ token ->isWhitespace () || $ token ->isGivenKind (T_ATTRIBUTE )) {
142+ continue ;
143+ }
144+
145+ // If we find 'new', it's an anonymous class
146+ if ($ token ->isGivenKind (T_NEW )) {
147+ return true ;
148+ }
149+
150+ // If we hit any other meaningful token, it's not anonymous
151+ break ;
152+ }
153+
154+ return false ;
155+ }
156+
129157 /**
130158 * @param array<string, string|array<string>> $annotations
131159 */
You can’t perform that action at this time.
0 commit comments