@@ -23,6 +23,11 @@ final class Xdebug implements Driver
2323 */
2424 private $ cacheNumLines = [];
2525
26+ /**
27+ * @var bool
28+ */
29+ private $ determineBranchCoverage = false ;
30+
2631 /**
2732 * @throws RuntimeException
2833 */
@@ -42,11 +47,16 @@ public function __construct()
4247 */
4348 public function start (bool $ determineUnusedAndDead = true ): void
4449 {
50+ $ flag = 0 ;
51+
4552 if ($ determineUnusedAndDead ) {
46- \xdebug_start_code_coverage (XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE );
47- } else {
48- \xdebug_start_code_coverage ();
53+ $ flag = XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE ;
54+ }
55+
56+ if ($ this ->determineBranchCoverage ) {
57+ $ flag |= XDEBUG_CC_BRANCH_CHECK ;
4958 }
59+ \xdebug_start_code_coverage ($ flag );
5060 }
5161
5262 /**
@@ -61,6 +71,17 @@ public function stop(): array
6171 return $ this ->cleanup ($ data );
6272 }
6373
74+ /**
75+ * Specify that branch coverage should be included with collected code coverage information.
76+ */
77+ public function setDetermineBranchCoverage (bool $ flag ): void
78+ {
79+ if ($ flag && \version_compare (\phpversion ('xdebug ' ), '2.3.2 ' , '< ' )) {
80+ throw new RuntimeException ('Branch coverage requires Xdebug 2.3.2 or newer ' );
81+ }
82+ $ this ->determineBranchCoverage = $ flag ;
83+ }
84+
6485 private function cleanup (array $ data ): array
6586 {
6687 foreach (\array_keys ($ data ) as $ file ) {
0 commit comments