@@ -496,27 +496,22 @@ private function applyIgnoredLinesFilter(RawCodeCoverageData $data): void
496
496
*/
497
497
private function addUncoveredFilesFromWhitelist (): void
498
498
{
499
- $ data = [];
500
499
$ uncoveredFiles = \array_diff (
501
500
$ this ->filter ->getWhitelist (),
502
501
\array_keys ($ this ->data ->getLineCoverage ())
503
502
);
504
503
505
504
foreach ($ uncoveredFiles as $ uncoveredFile ) {
506
- if (!\file_exists ($ uncoveredFile )) {
507
- continue ;
508
- }
509
-
510
- $ data [$ uncoveredFile ] = [];
511
-
512
- $ lines = \count (\file ($ uncoveredFile ));
505
+ if (\file_exists ($ uncoveredFile )) {
506
+ if ($ this ->cacheTokens ) {
507
+ $ tokens = \PHP_Token_Stream_CachingFactory::get ($ uncoveredFile );
508
+ } else {
509
+ $ tokens = new \PHP_Token_Stream ($ uncoveredFile );
510
+ }
513
511
514
- for ($ i = 1 ; $ i <= $ lines ; $ i ++) {
515
- $ data [$ uncoveredFile ][$ i ] = Driver::LINE_NOT_EXECUTED ;
512
+ $ this ->append (RawCodeCoverageData::fromUncoveredFile ($ uncoveredFile , $ tokens ), self ::UNCOVERED_FILES_FROM_WHITELIST );
516
513
}
517
514
}
518
-
519
- $ this ->append (RawCodeCoverageData::fromXdebugWithoutPathCoverage ($ data ), self ::UNCOVERED_FILES_FROM_WHITELIST );
520
515
}
521
516
522
517
private function getLinesToBeIgnored (string $ fileName ): array
@@ -540,60 +535,12 @@ private function getLinesToBeIgnoredInner(string $fileName): array
540
535
541
536
$ lines = \file ($ fileName );
542
537
543
- foreach ($ lines as $ index => $ line ) {
544
- if (!\trim ($ line )) {
545
- $ this ->ignoredLines [$ fileName ][] = $ index + 1 ;
546
- }
547
- }
548
-
549
538
if ($ this ->cacheTokens ) {
550
539
$ tokens = \PHP_Token_Stream_CachingFactory::get ($ fileName );
551
540
} else {
552
541
$ tokens = new \PHP_Token_Stream ($ fileName );
553
542
}
554
543
555
- foreach ($ tokens ->getInterfaces () as $ interface ) {
556
- $ interfaceStartLine = $ interface ['startLine ' ];
557
- $ interfaceEndLine = $ interface ['endLine ' ];
558
-
559
- foreach (\range ($ interfaceStartLine , $ interfaceEndLine ) as $ line ) {
560
- $ this ->ignoredLines [$ fileName ][] = $ line ;
561
- }
562
- }
563
-
564
- foreach (\array_merge ($ tokens ->getClasses (), $ tokens ->getTraits ()) as $ classOrTrait ) {
565
- $ classOrTraitStartLine = $ classOrTrait ['startLine ' ];
566
- $ classOrTraitEndLine = $ classOrTrait ['endLine ' ];
567
-
568
- if (empty ($ classOrTrait ['methods ' ])) {
569
- foreach (\range ($ classOrTraitStartLine , $ classOrTraitEndLine ) as $ line ) {
570
- $ this ->ignoredLines [$ fileName ][] = $ line ;
571
- }
572
-
573
- continue ;
574
- }
575
-
576
- $ firstMethod = \array_shift ($ classOrTrait ['methods ' ]);
577
- $ firstMethodStartLine = $ firstMethod ['startLine ' ];
578
- $ lastMethodEndLine = $ firstMethod ['endLine ' ];
579
-
580
- do {
581
- $ lastMethod = \array_pop ($ classOrTrait ['methods ' ]);
582
- } while ($ lastMethod !== null && 0 === \strpos ($ lastMethod ['signature ' ], 'anonymousFunction ' ));
583
-
584
- if ($ lastMethod !== null ) {
585
- $ lastMethodEndLine = $ lastMethod ['endLine ' ];
586
- }
587
-
588
- foreach (\range ($ classOrTraitStartLine , $ firstMethodStartLine ) as $ line ) {
589
- $ this ->ignoredLines [$ fileName ][] = $ line ;
590
- }
591
-
592
- foreach (\range ($ lastMethodEndLine + 1 , $ classOrTraitEndLine ) as $ line ) {
593
- $ this ->ignoredLines [$ fileName ][] = $ line ;
594
- }
595
- }
596
-
597
544
if ($ this ->disableIgnoredLines ) {
598
545
$ this ->ignoredLines [$ fileName ] = \array_unique ($ this ->ignoredLines [$ fileName ]);
599
546
\sort ($ this ->ignoredLines [$ fileName ]);
@@ -623,29 +570,10 @@ private function getLinesToBeIgnoredInner(string $fileName): array
623
570
$ stop = true ;
624
571
}
625
572
626
- if (!$ ignore ) {
627
- $ start = $ token ->getLine ();
628
- $ end = $ start + \substr_count ((string ) $ token , "\n" );
629
-
630
- // Do not ignore the first line when there is a token
631
- // before the comment
632
- if (0 !== \strpos ($ _token , $ _line )) {
633
- $ start ++;
634
- }
635
-
636
- for ($ i = $ start ; $ i < $ end ; $ i ++) {
637
- $ this ->ignoredLines [$ fileName ][] = $ i ;
638
- }
639
-
640
- // A DOC_COMMENT token or a COMMENT token starting with "/*"
641
- // does not contain the final \n character in its text
642
- if (isset ($ lines [$ i - 1 ]) && 0 === \strpos ($ _token , '/* ' ) && '*/ ' === \substr (\trim ($ lines [$ i - 1 ]), -2 )) {
643
- $ this ->ignoredLines [$ fileName ][] = $ i ;
644
- }
645
- }
646
-
647
573
break ;
648
574
575
+ // Intentional fallthrough
576
+
649
577
case \PHP_Token_INTERFACE::class:
650
578
case \PHP_Token_TRAIT::class:
651
579
case \PHP_Token_CLASS::class:
@@ -654,8 +582,6 @@ private function getLinesToBeIgnoredInner(string $fileName): array
654
582
655
583
$ docblock = (string ) $ token ->getDocblock ();
656
584
657
- $ this ->ignoredLines [$ fileName ][] = $ token ->getLine ();
658
-
659
585
if (\strpos ($ docblock , '@codeCoverageIgnore ' ) || ($ this ->ignoreDeprecatedCode && \strpos ($ docblock , '@deprecated ' ))) {
660
586
$ endLine = $ token ->getEndLine ();
661
587
@@ -664,20 +590,6 @@ private function getLinesToBeIgnoredInner(string $fileName): array
664
590
}
665
591
}
666
592
667
- break ;
668
-
669
- /* @noinspection PhpMissingBreakStatementInspection */
670
- case \PHP_Token_NAMESPACE::class:
671
- $ this ->ignoredLines [$ fileName ][] = $ token ->getEndLine ();
672
-
673
- // Intentional fallthrough
674
- case \PHP_Token_DECLARE::class:
675
- case \PHP_Token_OPEN_TAG::class:
676
- case \PHP_Token_CLOSE_TAG::class:
677
- case \PHP_Token_USE::class:
678
- case \PHP_Token_USE_FUNCTION::class:
679
- $ this ->ignoredLines [$ fileName ][] = $ token ->getLine ();
680
-
681
593
break ;
682
594
}
683
595
@@ -691,8 +603,6 @@ private function getLinesToBeIgnoredInner(string $fileName): array
691
603
}
692
604
}
693
605
694
- $ this ->ignoredLines [$ fileName ][] = \count ($ lines ) + 1 ;
695
-
696
606
$ this ->ignoredLines [$ fileName ] = \array_unique (
697
607
$ this ->ignoredLines [$ fileName ]
698
608
);
0 commit comments