File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed
Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -134,11 +134,29 @@ protected function applyFix(SplFileInfo $file, Tokens $tokens): void
134134 private function isAnonymousClass (Tokens $ tokens , int $ classIndex ): bool
135135 {
136136 // Look backwards for 'new' keyword
137+ $ insideAttribute = false ;
137138 for ($ i = $ classIndex - 1 ; $ i >= 0 ; --$ i ) {
138139 $ token = $ tokens [$ i ];
139140
140- // Skip whitespace and attributes
141- if ($ token ->isWhitespace () || $ token ->isGivenKind (T_ATTRIBUTE )) {
141+ // Skip whitespace
142+ if ($ token ->isWhitespace ()) {
143+ continue ;
144+ }
145+
146+ // When going backwards, ']' marks the end of an attribute (we enter it)
147+ if ('] ' === $ token ->getContent ()) {
148+ $ insideAttribute = true ;
149+ continue ;
150+ }
151+
152+ // T_ATTRIBUTE '#[' marks the start of an attribute (we exit it when going backwards)
153+ if ($ token ->isGivenKind ([T_ATTRIBUTE , T_FINAL , T_READONLY ])) {
154+ $ insideAttribute = false ;
155+ continue ;
156+ }
157+
158+ // Skip everything inside attributes
159+ if ($ insideAttribute ) {
142160 continue ;
143161 }
144162
You can’t perform that action at this time.
0 commit comments