@@ -81,22 +81,19 @@ class PHP_CodeCoverage
81
81
*/
82
82
private $ tests = [];
83
83
84
- /**
85
- * @var bool
86
- */
87
- private $ pathCoverage ;
88
-
89
84
/**
90
85
* Constructor.
91
86
*
92
87
* @param PHP_CodeCoverage_Driver $driver
93
88
* @param PHP_CodeCoverage_Filter $filter
94
- * @param bool $pathCoverage
89
+ * @param null| bool $pathCoverage `null` enables path coverage if supported.
95
90
* @throws PHP_CodeCoverage_InvalidArgumentException
96
91
*/
97
- public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null , $ pathCoverage = true )
92
+ public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null , $ pathCoverage = null )
98
93
{
99
- if (!is_bool ($ pathCoverage )) {
94
+ if ($ pathCoverage === null ) {
95
+ $ pathCoverage = version_compare (phpversion ('xdebug ' ), '2.3.2 ' , '>= ' );
96
+ } elseif (!is_bool ($ pathCoverage )) {
100
97
throw PHP_CodeCoverage_InvalidArgumentException::create (
101
98
3 ,
102
99
'boolean '
@@ -113,7 +110,6 @@ public function __construct(PHP_CodeCoverage_Driver $driver = null, PHP_CodeCove
113
110
114
111
$ this ->driver = $ driver ;
115
112
$ this ->filter = $ filter ;
116
- $ this ->pathCoverage = $ pathCoverage ;
117
113
}
118
114
119
115
/**
@@ -600,7 +596,11 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data)
600
596
continue ;
601
597
}
602
598
603
- $ this ->data [$ file ] = ['lines ' => []];
599
+ $ this ->data [$ file ] = [
600
+ 'lines ' => [],
601
+ 'branches ' =>[],
602
+ 'paths ' => [],
603
+ ];
604
604
605
605
foreach ($ fileData ['lines ' ] as $ lineNumber => $ flag ) {
606
606
if ($ flag === PHP_CodeCoverage_Driver::LINE_NOT_EXECUTABLE ) {
@@ -613,26 +613,21 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data)
613
613
}
614
614
}
615
615
616
- if ($ this -> pathCoverage ) {
617
- $ this ->data [$ file ]['branches ' ] = [];
618
- $ this ->data [$ file ]['paths ' ] = [ ];
616
+ foreach ($ fileData [ ' functions ' ] as $ functionName => $ functionData ) {
617
+ $ this ->data [$ file ]['branches ' ][ $ functionName ] = [];
618
+ $ this ->data [$ file ]['paths ' ][ $ functionName ] = $ functionData [ ' paths ' ];
619
619
620
- foreach ($ fileData ['functions ' ] as $ functionName => $ functionData ) {
621
- $ this ->data [$ file ]['branches ' ][$ functionName ] = [];
622
- $ this ->data [$ file ]['paths ' ][$ functionName ] = $ functionData ['paths ' ];
623
-
624
- foreach ($ functionData ['branches ' ] as $ index => $ branch ) {
625
- $ this ->data [$ file ]['branches ' ][$ functionName ][$ index ] = [
626
- 'hit ' => $ branch ['hit ' ],
627
- 'line_start ' => $ branch ['line_start ' ],
628
- 'line_end ' => $ branch ['line_end ' ],
629
- 'tests ' => []
630
- ];
620
+ foreach ($ functionData ['branches ' ] as $ index => $ branch ) {
621
+ $ this ->data [$ file ]['branches ' ][$ functionName ][$ index ] = [
622
+ 'hit ' => $ branch ['hit ' ],
623
+ 'line_start ' => $ branch ['line_start ' ],
624
+ 'line_end ' => $ branch ['line_end ' ],
625
+ 'tests ' => []
626
+ ];
631
627
632
- for ($ i = $ branch ['line_start ' ]; $ i < $ branch ['line_end ' ]; $ i ++) {
633
- if (isset ($ this ->data [$ file ]['lines ' ][$ i ])) {
634
- $ this ->data [$ file ]['lines ' ][$ i ]['pathCovered ' ] = (bool ) $ branch ['hit ' ];
635
- }
628
+ for ($ i = $ branch ['line_start ' ]; $ i < $ branch ['line_end ' ]; $ i ++) {
629
+ if (isset ($ this ->data [$ file ]['lines ' ][$ i ])) {
630
+ $ this ->data [$ file ]['lines ' ][$ i ]['pathCovered ' ] = (bool ) $ branch ['hit ' ];
636
631
}
637
632
}
638
633
}
0 commit comments