18
18
use Roave \BetterReflection \Reflection \Exception \NotAClassReflection ;
19
19
use Roave \BetterReflection \Reflection \Exception \NotAnInterfaceReflection ;
20
20
use Roave \BetterReflection \Reflector \Exception \IdentifierNotFound ;
21
- use function array_fill_keys ;
22
21
use function array_key_exists ;
23
22
use function array_unique ;
24
23
@@ -165,7 +164,7 @@ public function analyseFile(
165
164
}
166
165
167
166
foreach ($ this ->getLinesToIgnore ($ node ) as $ lineToIgnore ) {
168
- $ linesToIgnore [] = $ lineToIgnore ;
167
+ $ linesToIgnore [$ scope -> getFileDescription ()][ $ lineToIgnore ] = true ;
169
168
}
170
169
171
170
try {
@@ -192,43 +191,42 @@ public function analyseFile(
192
191
$ scope ,
193
192
$ nodeCallback
194
193
);
195
- $ linesToIgnoreKeys = array_fill_keys ($ linesToIgnore , true );
196
- $ unmatchedLineIgnores = $ linesToIgnoreKeys ;
194
+ $ unmatchedLineIgnores = $ linesToIgnore ;
197
195
foreach ($ temporaryFileErrors as $ tmpFileError ) {
198
196
$ line = $ tmpFileError ->getLine ();
199
197
if (
200
198
$ line !== null
201
199
&& $ tmpFileError ->canBeIgnored ()
202
- && array_key_exists ($ line , $ linesToIgnoreKeys )
200
+ && array_key_exists ($ tmpFileError ->getFile (), $ linesToIgnore )
201
+ && array_key_exists ($ line , $ linesToIgnore [$ tmpFileError ->getFile ()])
203
202
) {
204
- unset($ unmatchedLineIgnores [$ line ]);
203
+ unset($ unmatchedLineIgnores [$ tmpFileError -> getFile ()][ $ line ]);
205
204
continue ;
206
205
}
207
206
208
207
$ fileErrors [] = $ tmpFileError ;
209
208
}
210
209
211
210
if ($ this ->reportUnmatchedIgnoredErrors ) {
212
- foreach (array_keys ($ unmatchedLineIgnores ) as $ line ) {
213
- $ traitFilePath = null ;
214
- if ($ scope ->isInTrait ()) {
215
- $ traitReflection = $ scope ->getTraitReflection ();
216
- if ($ traitReflection ->getFileName () !== false ) {
217
- $ traitFilePath = $ traitReflection ->getFileName ();
218
- }
211
+ foreach ($ unmatchedLineIgnores as $ ignoredFile => $ lines ) {
212
+ if ($ ignoredFile !== $ file ) {
213
+ continue ;
214
+ }
215
+
216
+ foreach (array_keys ($ lines ) as $ line ) {
217
+ $ fileErrors [] = new Error (
218
+ sprintf ('No error to ignore is reported on line %d. ' , $ line ),
219
+ $ scope ->getFileDescription (),
220
+ $ line ,
221
+ false ,
222
+ $ scope ->getFile (),
223
+ null ,
224
+ null ,
225
+ null ,
226
+ null ,
227
+ 'ignoredError.unmatchedOnLine '
228
+ );
219
229
}
220
- $ fileErrors [] = new Error (
221
- sprintf ('No error to ignore is reported on line %d. ' , $ line ),
222
- $ scope ->getFileDescription (),
223
- $ line ,
224
- false ,
225
- $ scope ->getFile (),
226
- $ traitFilePath ,
227
- null ,
228
- null ,
229
- null ,
230
- 'ignoredError.unmatchedOnLine '
231
- );
232
230
}
233
231
}
234
232
} catch (\PhpParser \Error $ e ) {
0 commit comments