@@ -86,25 +86,39 @@ class PHP_CodeCoverage
86
86
*/
87
87
private $ tests = [];
88
88
89
+ /**
90
+ * @var bool
91
+ */
92
+ private $ pathCoverage = false ;
93
+
89
94
/**
90
95
* Constructor.
91
96
*
92
97
* @param PHP_CodeCoverage_Driver $driver
93
98
* @param PHP_CodeCoverage_Filter $filter
99
+ * @param bool $pathCoverage
94
100
* @throws PHP_CodeCoverage_RuntimeException
95
101
*/
96
- public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null )
102
+ public function __construct (PHP_CodeCoverage_Driver $ driver = null , PHP_CodeCoverage_Filter $ filter = null , $ pathCoverage = true )
97
103
{
104
+ if (!is_bool ($ pathCoverage )) {
105
+ throw PHP_CodeCoverage_Util_InvalidArgumentHelper::factory (
106
+ 3 ,
107
+ 'boolean '
108
+ );
109
+ }
110
+
98
111
if ($ driver === null ) {
99
- $ driver = $ this ->selectDriver ();
112
+ $ driver = $ this ->selectDriver ($ pathCoverage );
100
113
}
101
114
102
115
if ($ filter === null ) {
103
116
$ filter = new PHP_CodeCoverage_Filter ;
104
117
}
105
118
106
- $ this ->driver = $ driver ;
107
- $ this ->filter = $ filter ;
119
+ $ this ->driver = $ driver ;
120
+ $ this ->filter = $ filter ;
121
+ $ this ->pathCoverage = $ pathCoverage ;
108
122
}
109
123
110
124
/**
@@ -312,15 +326,15 @@ public function append(array $data, $id = null, $append = true, $linesToBeCovere
312
326
313
327
$ this ->tests [$ id ] = ['size ' => $ size , 'status ' => $ status ];
314
328
315
- foreach ($ data as $ file => $ lines ) {
329
+ foreach ($ data as $ file => $ fileData ) {
316
330
if (!$ this ->filter ->isFile ($ file )) {
317
331
continue ;
318
332
}
319
333
320
- foreach ($ lines as $ k => $ v ) {
334
+ foreach ($ fileData [ ' lines ' ] as $ k => $ v ) {
321
335
if ($ v == PHP_CodeCoverage_Driver::LINE_EXECUTED ) {
322
- if (empty ($ this ->data [$ file ][$ k ]) || !in_array ($ id , $ this ->data [$ file ][$ k ])) {
323
- $ this ->data [$ file ][$ k ][] = $ id ;
336
+ if (empty ($ this ->data [$ file ][' lines ' ][ $ k ]) || !in_array ($ id , $ this ->data [$ file][ ' lines ' ][$ k ])) {
337
+ $ this ->data [$ file ][' lines ' ][ $ k ][] = $ id ;
324
338
}
325
339
}
326
340
}
@@ -338,22 +352,22 @@ public function merge(PHP_CodeCoverage $that)
338
352
array_merge ($ this ->filter ->getWhitelistedFiles (), $ that ->filter ()->getWhitelistedFiles ())
339
353
);
340
354
341
- foreach ($ that ->data as $ file => $ lines ) {
355
+ foreach ($ that ->getData () as $ file => $ fileData ) {
342
356
if (!isset ($ this ->data [$ file ])) {
343
- if (!$ this ->filter ->isFiltered ($ file )) {
344
- $ this ->data [$ file ] = $ lines ;
357
+ if (!$ that ->filter () ->isFiltered ($ file )) {
358
+ $ this ->data [$ file ] = [ ' lines ' => $ fileData [ ' lines ' ]] ;
345
359
}
346
360
347
361
continue ;
348
362
}
349
363
350
- foreach ($ lines as $ line => $ data ) {
364
+ foreach ($ fileData [ ' lines ' ] as $ line => $ data ) {
351
365
if ($ data !== null ) {
352
- if (!isset ($ this ->data [$ file ][$ line ])) {
353
- $ this ->data [$ file ][$ line ] = $ data ;
366
+ if (!isset ($ this ->data [$ file ][' lines ' ][ $ line ])) {
367
+ $ this ->data [$ file ][' lines ' ][ $ line ] = $ data ;
354
368
} else {
355
- $ this ->data [$ file ][$ line ] = array_unique (
356
- array_merge ($ this ->data [$ file ][$ line ], $ data )
369
+ $ this ->data [$ file ][' lines ' ][ $ line ] = array_unique (
370
+ array_merge ($ this ->data [$ file ][' lines ' ][ $ line ], $ data )
357
371
);
358
372
}
359
373
}
@@ -498,7 +512,7 @@ private function applyCoversAnnotationFilter(array &$data, $linesToBeCovered, ar
498
512
{
499
513
if ($ linesToBeCovered === false ||
500
514
($ this ->forceCoversAnnotation && empty ($ linesToBeCovered ))) {
501
- $ data = [];
515
+ $ data = [' lines ' => [] ];
502
516
503
517
return ;
504
518
}
@@ -520,8 +534,8 @@ private function applyCoversAnnotationFilter(array &$data, $linesToBeCovered, ar
520
534
foreach (array_keys ($ data ) as $ filename ) {
521
535
$ _linesToBeCovered = array_flip ($ linesToBeCovered [$ filename ]);
522
536
523
- $ data [$ filename ] = array_intersect_key (
524
- $ data [$ filename ],
537
+ $ data [$ filename ][ ' lines ' ] = array_intersect_key (
538
+ $ data [$ filename ][ ' lines ' ] ,
525
539
$ _linesToBeCovered
526
540
);
527
541
}
@@ -554,7 +568,7 @@ private function applyIgnoredLinesFilter(array &$data)
554
568
}
555
569
556
570
foreach ($ this ->getLinesToBeIgnored ($ filename ) as $ line ) {
557
- unset($ data [$ filename ][$ line ]);
571
+ unset($ data [$ filename ][' lines ' ][ $ line ]);
558
572
}
559
573
}
560
574
}
@@ -565,12 +579,37 @@ private function applyIgnoredLinesFilter(array &$data)
565
579
*/
566
580
private function initializeFilesThatAreSeenTheFirstTime (array $ data )
567
581
{
568
- foreach ($ data as $ file => $ lines ) {
582
+ foreach ($ data as $ file => $ fileData ) {
569
583
if ($ this ->filter ->isFile ($ file ) && !isset ($ this ->data [$ file ])) {
570
- $ this ->data [$ file ] = [];
584
+ $ this ->data [$ file ] = ['lines ' => []];
585
+
586
+ if ($ this ->pathCoverage ) {
587
+ $ this ->data [$ file ]['branches ' ] = [];
588
+ $ this ->data [$ file ]['paths ' ] = [];
589
+
590
+ foreach ($ fileData ['functions ' ] as $ functionName => $ functionData ) {
591
+ $ this ->data [$ file ]['branches ' ][$ functionName ] = [];
592
+ $ this ->data [$ file ]['paths ' ][$ functionName ] = [];
593
+
594
+ foreach ($ functionData ['branches ' ] as $ branch ) {
595
+ $ this ->data [$ file ]['branches ' ][$ functionName ][] = [
596
+ 'line_start ' => $ branch ['line_start ' ],
597
+ 'line_end ' => $ branch ['line_end ' ],
598
+ 'tests ' => []
599
+ ];
600
+ }
601
+
602
+ foreach ($ functionData ['paths ' ] as $ path ) {
603
+ $ this ->data [$ file ]['paths ' ][$ functionName ][] = [
604
+ 'path ' => $ path ['path ' ],
605
+ 'tests ' => []
606
+ ];
607
+ }
608
+ }
609
+ }
571
610
572
- foreach ($ lines as $ k => $ v ) {
573
- $ this ->data [$ file ][$ k ] = $ v == -2 ? null : [];
611
+ foreach ($ fileData [ ' lines ' ] as $ lineNumber => $ flag ) {
612
+ $ this ->data [$ file ][' lines ' ][ $ lineNumber ] = $ flag == -2 ? null : [];
574
613
}
575
614
}
576
615
}
@@ -599,12 +638,12 @@ private function addUncoveredFilesFromWhitelist()
599
638
$ uncoveredFiles
600
639
);
601
640
} else {
602
- $ data [$ uncoveredFile ] = [];
641
+ $ data [$ uncoveredFile ] = [' lines ' => [] ];
603
642
604
643
$ lines = count (file ($ uncoveredFile ));
605
644
606
645
for ($ i = 1 ; $ i <= $ lines ; $ i ++) {
607
- $ data [$ uncoveredFile ][$ i ] = PHP_CodeCoverage_Driver::LINE_NOT_EXECUTED ;
646
+ $ data [$ uncoveredFile ][' lines ' ][ $ i ] = PHP_CodeCoverage_Driver::LINE_NOT_EXECUTED ;
608
647
}
609
648
}
610
649
}
@@ -632,7 +671,7 @@ private function processUncoveredFileFromWhitelist($uncoveredFile, array &$data,
632
671
}
633
672
}
634
673
635
- $ data [$ file ] = $ fileCoverage ;
674
+ $ data [$ file ] = [ ' lines ' => $ fileCoverage] ;
636
675
}
637
676
}
638
677
}
@@ -827,8 +866,8 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
827
866
828
867
$ message = '' ;
829
868
830
- foreach ($ data as $ file => $ _data ) {
831
- foreach ($ _data as $ line => $ flag ) {
869
+ foreach ($ data as $ file => $ fileData ) {
870
+ foreach ($ fileData [ ' lines ' ] as $ line => $ flag ) {
832
871
if ($ flag == 1 &&
833
872
(!isset ($ allowedLines [$ file ]) ||
834
873
!isset ($ allowedLines [$ file ][$ line ]))) {
@@ -890,10 +929,11 @@ private function getAllowedLines(array $linesToBeCovered, array $linesToBeUsed)
890
929
}
891
930
892
931
/**
932
+ * @param bool $pathCoverage
893
933
* @return PHP_CodeCoverage_Driver
894
934
* @throws PHP_CodeCoverage_RuntimeException
895
935
*/
896
- private function selectDriver ()
936
+ private function selectDriver ($ pathCoverage )
897
937
{
898
938
$ runtime = new Runtime ;
899
939
@@ -906,7 +946,7 @@ private function selectDriver()
906
946
} elseif ($ runtime ->isPHPDBG ()) {
907
947
return new PHP_CodeCoverage_Driver_PHPDBG ;
908
948
} else {
909
- return new PHP_CodeCoverage_Driver_Xdebug ;
949
+ return new PHP_CodeCoverage_Driver_Xdebug ( $ pathCoverage ) ;
910
950
}
911
951
}
912
952
}
0 commit comments