99 */
1010namespace SebastianBergmann \CodeCoverage \Driver ;
1111
12+ use SebastianBergmann \CodeCoverage \Filter ;
1213use SebastianBergmann \CodeCoverage \RuntimeException ;
1314
1415/**
@@ -23,10 +24,15 @@ final class Xdebug implements Driver
2324 */
2425 private $ cacheNumLines = [];
2526
27+ /**
28+ * @var Filter
29+ */
30+ private $ filter ;
31+
2632 /**
2733 * @throws RuntimeException
2834 */
29- public function __construct ()
35+ public function __construct (Filter $ filter = null )
3036 {
3137 if (!\extension_loaded ('xdebug ' )) {
3238 throw new RuntimeException ('This driver requires Xdebug ' );
@@ -35,6 +41,12 @@ public function __construct()
3541 if (!\ini_get ('xdebug.coverage_enable ' )) {
3642 throw new RuntimeException ('xdebug.coverage_enable=On has to be set in php.ini ' );
3743 }
44+
45+ if ($ filter === null ) {
46+ $ filter = new Filter ;
47+ }
48+
49+ $ this ->filter = $ filter ;
3850 }
3951
4052 /**
@@ -66,13 +78,15 @@ private function cleanup(array $data): array
6678 foreach (\array_keys ($ data ) as $ file ) {
6779 unset($ data [$ file ][0 ]);
6880
69- if (\strpos ($ file , 'xdebug://debug-eval ' ) !== 0 && $ file !== 'Standard input code ' && \file_exists ($ file )) {
70- $ numLines = $ this ->getNumberOfLinesInFile ($ file );
81+ if (!$ this ->filter ->isFile ($ file )) {
82+ continue ;
83+ }
84+
85+ $ numLines = $ this ->getNumberOfLinesInFile ($ file );
7186
72- foreach (\array_keys ($ data [$ file ]) as $ line ) {
73- if ($ line > $ numLines ) {
74- unset($ data [$ file ][$ line ]);
75- }
87+ foreach (\array_keys ($ data [$ file ]) as $ line ) {
88+ if ($ line > $ numLines ) {
89+ unset($ data [$ file ][$ line ]);
7690 }
7791 }
7892 }
0 commit comments