1818use Roave \BetterReflection \Reflection \Exception \NotAClassReflection ;
1919use Roave \BetterReflection \Reflection \Exception \NotAnInterfaceReflection ;
2020use Roave \BetterReflection \Reflector \Exception \IdentifierNotFound ;
21- use function array_fill_keys ;
2221use function array_key_exists ;
2322use function array_unique ;
2423
@@ -165,7 +164,7 @@ public function analyseFile(
165164 }
166165
167166 foreach ($ this ->getLinesToIgnore ($ node ) as $ lineToIgnore ) {
168- $ linesToIgnore [] = $ lineToIgnore ;
167+ $ linesToIgnore [$ scope -> getFileDescription ()][ $ lineToIgnore ] = true ;
169168 }
170169
171170 try {
@@ -192,43 +191,42 @@ public function analyseFile(
192191 $ scope ,
193192 $ nodeCallback
194193 );
195- $ linesToIgnoreKeys = array_fill_keys ($ linesToIgnore , true );
196- $ unmatchedLineIgnores = $ linesToIgnoreKeys ;
194+ $ unmatchedLineIgnores = $ linesToIgnore ;
197195 foreach ($ temporaryFileErrors as $ tmpFileError ) {
198196 $ line = $ tmpFileError ->getLine ();
199197 if (
200198 $ line !== null
201199 && $ tmpFileError ->canBeIgnored ()
202- && array_key_exists ($ line , $ linesToIgnoreKeys )
200+ && array_key_exists ($ tmpFileError ->getFile (), $ linesToIgnore )
201+ && array_key_exists ($ line , $ linesToIgnore [$ tmpFileError ->getFile ()])
203202 ) {
204- unset($ unmatchedLineIgnores [$ line ]);
203+ unset($ unmatchedLineIgnores [$ tmpFileError -> getFile ()][ $ line ]);
205204 continue ;
206205 }
207206
208207 $ fileErrors [] = $ tmpFileError ;
209208 }
210209
211210 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+ );
219229 }
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- );
232230 }
233231 }
234232 } catch (\PhpParser \Error $ e ) {
0 commit comments