1515use PHPStan \Parser \Parser ;
1616use PHPStan \Parser \ParserErrorsException ;
1717use PHPStan \Rules \Registry as RuleRegistry ;
18- use function array_key_exists ;
1918use function array_keys ;
2019use function array_merge ;
2120use function array_unique ;
2221use function array_values ;
2322use function count ;
2423use function error_reporting ;
2524use function get_class ;
26- use function is_array ;
2725use function is_dir ;
2826use function is_file ;
2927use function restore_error_handler ;
@@ -43,6 +41,7 @@ public function __construct(
4341 private Parser $ parser ,
4442 private DependencyResolver $ dependencyResolver ,
4543 private RuleErrorTransformer $ ruleErrorTransformer ,
44+ private LocalIgnoresProcessor $ localIgnoresProcessor ,
4645 private bool $ reportUnmatchedIgnoredErrors ,
4746 )
4847 {
@@ -176,69 +175,20 @@ public function analyseFile(
176175 $ scope ,
177176 $ nodeCallback ,
178177 );
179- foreach ($ temporaryFileErrors as $ tmpFileError ) {
180- $ line = $ tmpFileError ->getLine ();
181- if (
182- $ line !== null
183- && $ tmpFileError ->canBeIgnored ()
184- && array_key_exists ($ tmpFileError ->getFile (), $ linesToIgnore )
185- && array_key_exists ($ line , $ linesToIgnore [$ tmpFileError ->getFile ()])
186- ) {
187- $ identifiers = $ linesToIgnore [$ tmpFileError ->getFile ()][$ line ];
188- if ($ identifiers === null ) {
189- $ locallyIgnoredErrors [] = $ tmpFileError ;
190- unset($ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ]);
191- continue ;
192- }
193-
194- if ($ tmpFileError ->getIdentifier () === null ) {
195- $ fileErrors [] = $ tmpFileError ;
196- continue ;
197- }
198-
199- foreach ($ identifiers as $ i => $ ignoredIdentifier ) {
200- if ($ ignoredIdentifier !== $ tmpFileError ->getIdentifier ()) {
201- continue ;
202- }
203-
204- unset($ identifiers [$ i ]);
205178
206- if (count ($ identifiers ) > 0 ) {
207- $ linesToIgnore [$ tmpFileError ->getFile ()][$ line ] = array_values ($ identifiers );
208- } else {
209- unset($ linesToIgnore [$ tmpFileError ->getFile ()][$ line ]);
210- }
211-
212- if (
213- array_key_exists ($ tmpFileError ->getFile (), $ unmatchedLineIgnores )
214- && array_key_exists ($ line , $ unmatchedLineIgnores [$ tmpFileError ->getFile ()])
215- ) {
216- $ unmatchedIgnoredIdentifiers = $ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ];
217- if (is_array ($ unmatchedIgnoredIdentifiers )) {
218- foreach ($ unmatchedIgnoredIdentifiers as $ j => $ unmatchedIgnoredIdentifier ) {
219- if ($ ignoredIdentifier !== $ unmatchedIgnoredIdentifier ) {
220- continue ;
221- }
222-
223- unset($ unmatchedIgnoredIdentifiers [$ j ]);
224-
225- if (count ($ unmatchedIgnoredIdentifiers ) > 0 ) {
226- $ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ] = array_values ($ unmatchedIgnoredIdentifiers );
227- } else {
228- unset($ unmatchedLineIgnores [$ tmpFileError ->getFile ()][$ line ]);
229- }
230- break ;
231- }
232- }
233- }
234-
235- $ locallyIgnoredErrors [] = $ tmpFileError ;
236- continue 2 ;
237- }
238- }
239-
240- $ fileErrors [] = $ tmpFileError ;
179+ $ localIgnoresProcessorResult = $ this ->localIgnoresProcessor ->process (
180+ $ temporaryFileErrors ,
181+ $ linesToIgnore ,
182+ $ unmatchedLineIgnores ,
183+ );
184+ foreach ($ localIgnoresProcessorResult ->getFileErrors () as $ fileError ) {
185+ $ fileErrors [] = $ fileError ;
186+ }
187+ foreach ($ localIgnoresProcessorResult ->getLocallyIgnoredErrors () as $ locallyIgnoredError ) {
188+ $ locallyIgnoredErrors [] = $ locallyIgnoredError ;
241189 }
190+ $ linesToIgnore = $ localIgnoresProcessorResult ->getLinesToIgnore ();
191+ $ unmatchedLineIgnores = $ localIgnoresProcessorResult ->getUnmatchedLineIgnores ();
242192
243193 if ($ this ->reportUnmatchedIgnoredErrors ) {
244194 foreach ($ unmatchedLineIgnores as $ ignoredFile => $ lines ) {
0 commit comments