@@ -474,7 +474,7 @@ public function testIgnoreNextLine(bool $reportUnmatchedIgnoredErrors): void
474474 __DIR__ . '/data/ignore-next-line.php ' ,
475475 ], true );
476476 $ this ->assertCount ($ reportUnmatchedIgnoredErrors ? 4 : 3 , $ result );
477- foreach ([10 , 30 , 34 ] as $ i => $ line ) {
477+ foreach ([10 , 20 , 24 ] as $ i => $ line ) {
478478 $ this ->assertArrayHasKey ($ i , $ result );
479479 $ this ->assertInstanceOf (Error::class, $ result [$ i ]);
480480 $ this ->assertSame ('Fail. ' , $ result [$ i ]->getMessage ());
@@ -487,8 +487,20 @@ public function testIgnoreNextLine(bool $reportUnmatchedIgnoredErrors): void
487487
488488 $ this ->assertArrayHasKey (3 , $ result );
489489 $ this ->assertInstanceOf (Error::class, $ result [3 ]);
490- $ this ->assertSame ('No error to ignore is reported on line 38. ' , $ result [3 ]->getMessage ());
491- $ this ->assertSame (38 , $ result [3 ]->getLine ());
490+ $ this ->assertSame ('No error to ignore is reported on line 28. ' , $ result [3 ]->getMessage ());
491+ $ this ->assertSame (28 , $ result [3 ]->getLine ());
492+ }
493+
494+ public function testIgnoreNextLineLegacyBehaviour (): void
495+ {
496+ $ result = $ this ->runAnalyser ([], false , [__DIR__ . '/data/ignore-next-line-legacy.php ' ], true , false );
497+
498+ foreach ([10 , 32 , 36 ] as $ i => $ line ) {
499+ $ this ->assertArrayHasKey ($ i , $ result );
500+ $ this ->assertInstanceOf (Error::class, $ result [$ i ]);
501+ $ this ->assertSame ('Fail. ' , $ result [$ i ]->getMessage ());
502+ $ this ->assertSame ($ line , $ result [$ i ]->getLine ());
503+ }
492504 }
493505
494506 /**
@@ -577,9 +589,10 @@ private function runAnalyser(
577589 bool $ reportUnmatchedIgnoredErrors ,
578590 $ filePaths ,
579591 bool $ onlyFiles ,
592+ bool $ enableIgnoreErrorsWithinPhpDocs = true ,
580593 ): array
581594 {
582- $ analyser = $ this ->createAnalyser ($ reportUnmatchedIgnoredErrors );
595+ $ analyser = $ this ->createAnalyser ($ reportUnmatchedIgnoredErrors, $ enableIgnoreErrorsWithinPhpDocs );
583596
584597 if (is_string ($ filePaths )) {
585598 $ filePaths = [$ filePaths ];
@@ -610,7 +623,7 @@ private function runAnalyser(
610623 );
611624 }
612625
613- private function createAnalyser (bool $ reportUnmatchedIgnoredErrors ): Analyser
626+ private function createAnalyser (bool $ reportUnmatchedIgnoredErrors, bool $ enableIgnoreErrorsWithinPhpDocs ): Analyser
614627 {
615628 $ ruleRegistry = new DirectRuleRegistry ([
616629 new AlwaysFailRule (),
@@ -658,6 +671,7 @@ private function createAnalyser(bool $reportUnmatchedIgnoredErrors): Analyser
658671 $ lexer ,
659672 new NameResolver (),
660673 self ::getContainer (),
674+ $ enableIgnoreErrorsWithinPhpDocs ,
661675 ),
662676 new DependencyResolver ($ fileHelper , $ reflectionProvider , new ExportedNodeResolver ($ fileTypeMapper , new ExprPrinter (new Printer ())), $ fileTypeMapper ),
663677 new RuleErrorTransformer (),
0 commit comments