@@ -91,12 +91,14 @@ class PHP_CodeCoverage
91
91
*
92
92
* @param PHP_CodeCoverage_Driver $driver
93
93
* @param PHP_CodeCoverage_Filter $filter
94
- * @param bool $pathCoverage
94
+ * @param null| bool $pathCoverage `null` enables path coverage if supported.
95
95
* @throws PHP_CodeCoverage_InvalidArgumentException
96
96
*/
97
- public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null , $ pathCoverage = true )
97
+ public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null , $ pathCoverage = null )
98
98
{
99
- if (!is_bool ($ pathCoverage )) {
99
+ if ($ pathCoverage === null ) {
100
+ $ pathCoverage = version_compare (phpversion ('xdebug ' ), '2.3.2 ' , '>= ' );
101
+ } elseif (!is_bool ($ pathCoverage )) {
100
102
throw PHP_CodeCoverage_InvalidArgumentException::create (
101
103
3 ,
102
104
'boolean '
@@ -340,18 +342,20 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
340
342
}
341
343
}
342
344
343
- foreach ($ fileData ['functions ' ] as $ function => $ functionCoverage ) {
344
- foreach ($ functionCoverage ['branches ' ] as $ branch => $ branchCoverage ) {
345
- if ($ branchCoverage ['hit ' ] === 1 ){
346
- $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['hit ' ] = 1 ;
347
- if (!in_array ($ id , $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ])) {
348
- $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ][] = $ id ;
345
+ if ($ this ->pathCoverage ) {
346
+ foreach ($ fileData ['functions ' ] as $ function => $ functionCoverage ) {
347
+ foreach ($ functionCoverage ['branches ' ] as $ branch => $ branchCoverage ) {
348
+ if ($ branchCoverage ['hit ' ] === 1 ) {
349
+ $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['hit ' ] = 1 ;
350
+ if (!in_array ($ id , $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ])) {
351
+ $ this ->data [$ file ]['branches ' ][$ function ][$ branch ]['tests ' ][] = $ id ;
352
+ }
349
353
}
350
354
}
351
- }
352
- foreach ( $ functionCoverage [ ' paths ' ] as $ path => $ pathCoverage ) {
353
- if ( $ pathCoverage [ ' hit ' ] === 1 && $ this ->data [$ file ]['paths ' ][$ function ][$ path ]['hit ' ] === 0 ){
354
- $ this -> data [ $ file ][ ' paths ' ][ $ function ][ $ path ][ ' hit ' ] = 1 ;
355
+ foreach ( $ functionCoverage [ ' paths ' ] as $ path => $ pathCoverage ) {
356
+ if ( $ pathCoverage [ ' hit ' ] === 1 && $ this -> data [ $ file ][ ' paths ' ][ $ function ][ $ path][ ' hit ' ] === 0 ) {
357
+ $ this ->data [$ file ]['paths ' ][$ function ][$ path ]['hit ' ] = 1 ;
358
+ }
355
359
}
356
360
}
357
361
}
@@ -380,15 +384,17 @@ public function merge(PHP_CodeCoverage $that)
380
384
381
385
foreach ($ fileData ['lines ' ] as $ line => $ data ) {
382
386
if ($ data !== null ) {
383
- if (!isset ($ this ->data [$ file ]['lines ' ][$ line ])) {
384
- $ this ->data [$ file ]['lines ' ][$ line ] = $ data ;
385
- } else {
386
- if ($ data ['pathCovered ' ]) {
387
- $ this ->data [$ file ]['lines ' ][$ line ]['pathCovered ' ] = $ data ['pathCovered ' ];
387
+ if ($ this ->pathCoverage ) {
388
+ if (!isset ($ this ->data [$ file ]['lines ' ][$ line ])) {
389
+ $ this ->data [$ file ]['lines ' ][$ line ] = $ data ;
390
+ } else {
391
+ if ($ data ['pathCovered ' ]) {
392
+ $ this ->data [$ file ]['lines ' ][$ line ]['pathCovered ' ] = $ data ['pathCovered ' ];
393
+ }
394
+ $ this ->data [$ file ]['lines ' ][$ line ]['tests ' ] = array_unique (
395
+ array_merge ($ this ->data [$ file ]['lines ' ][$ line ]['tests ' ], $ data ['tests ' ])
396
+ );
388
397
}
389
- $ this ->data [$ file ]['lines ' ][$ line ]['tests ' ] = array_unique (
390
- array_merge ($ this ->data [$ file ]['lines ' ][$ line ]['tests ' ], $ data ['tests ' ])
391
- );
392
398
}
393
399
}
394
400
}
0 commit comments