@@ -782,10 +782,50 @@ private function getLinesToBeIgnored($filename)
782782 $ tokens = new \PHP_Token_Stream ($ filename );
783783 }
784784
785- $ classes = \array_merge ($ tokens ->getClasses (), $ tokens ->getTraits ());
786- $ tokens = $ tokens ->tokens ();
785+ foreach ($ tokens ->getInterfaces () as $ interface ) {
786+ $ interfaceStartLine = $ interface ['startLine ' ];
787+ $ interfaceEndLine = $ interface ['endLine ' ];
787788
788- foreach ($ tokens as $ token ) {
789+ foreach (range ($ interfaceStartLine , $ interfaceEndLine ) as $ line ) {
790+ $ this ->ignoredLines [$ filename ][] = $ line ;
791+ }
792+ }
793+
794+ foreach (\array_merge ($ tokens ->getClasses (), $ tokens ->getTraits ()) as $ classOrTrait ) {
795+ $ classOrTraitStartLine = $ classOrTrait ['startLine ' ];
796+ $ classOrTraitEndLine = $ classOrTrait ['endLine ' ];
797+
798+ if (empty ($ classOrTrait ['methods ' ])) {
799+ foreach (range ($ classOrTraitStartLine , $ classOrTraitEndLine ) as $ line ) {
800+ $ this ->ignoredLines [$ filename ][] = $ line ;
801+ }
802+
803+ continue ;
804+ }
805+
806+ $ firstMethod = \array_shift ($ classOrTrait ['methods ' ]);
807+ $ firstMethodStartLine = $ firstMethod ['startLine ' ];
808+ $ firstMethodEndLine = $ firstMethod ['endLine ' ];
809+ $ lastMethodEndLine = $ firstMethodEndLine ;
810+
811+ do {
812+ $ lastMethod = \array_pop ($ classOrTrait ['methods ' ]);
813+ } while ($ lastMethod !== null && 0 === \strpos ($ lastMethod ['signature ' ], 'anonymous function ' ));
814+
815+ if ($ lastMethod !== null ) {
816+ $ lastMethodEndLine = $ lastMethod ['endLine ' ];
817+ }
818+
819+ foreach (range ($ classOrTraitStartLine , $ firstMethodStartLine ) as $ line ) {
820+ $ this ->ignoredLines [$ filename ][] = $ line ;
821+ }
822+
823+ foreach (range ($ lastMethodEndLine + 1 , $ classOrTraitEndLine ) as $ line ) {
824+ $ this ->ignoredLines [$ filename ][] = $ line ;
825+ }
826+ }
827+
828+ foreach ($ tokens ->tokens () as $ token ) {
789829 switch (\get_class ($ token )) {
790830 case \PHP_Token_COMMENT::class:
791831 case \PHP_Token_DOC_COMMENT::class:
@@ -843,36 +883,6 @@ private function getLinesToBeIgnored($filename)
843883 for ($ i = $ token ->getLine (); $ i <= $ endLine ; $ i ++) {
844884 $ this ->ignoredLines [$ filename ][] = $ i ;
845885 }
846- } elseif ($ token instanceof \PHP_Token_INTERFACE ||
847- $ token instanceof \PHP_Token_TRAIT ||
848- $ token instanceof \PHP_Token_CLASS) {
849- if (empty ($ classes [$ token ->getName ()]['methods ' ])) {
850- for ($ i = $ token ->getLine (); $ i <= $ token ->getEndLine (); $ i ++) {
851- $ this ->ignoredLines [$ filename ][] = $ i ;
852- }
853- } else {
854- $ firstMethod = \array_shift (
855- $ classes [$ token ->getName ()]['methods ' ]
856- );
857-
858- do {
859- $ lastMethod = \array_pop (
860- $ classes [$ token ->getName ()]['methods ' ]
861- );
862- } while ($ lastMethod !== null && 0 === \strpos ($ lastMethod ['signature ' ], 'anonymous function ' ));
863-
864- if ($ lastMethod === null ) {
865- $ lastMethod = $ firstMethod ;
866- }
867-
868- for ($ i = $ token ->getLine (); $ i < $ firstMethod ['startLine ' ]; $ i ++) {
869- $ this ->ignoredLines [$ filename ][] = $ i ;
870- }
871-
872- for ($ i = $ token ->getEndLine (); $ i > $ lastMethod ['endLine ' ]; $ i --) {
873- $ this ->ignoredLines [$ filename ][] = $ i ;
874- }
875- }
876886 }
877887
878888 break ;
0 commit comments