@@ -255,7 +255,7 @@ public function start($id, bool $clear = false): void
255
255
* @throws InvalidArgumentException
256
256
* @throws \ReflectionException
257
257
*/
258
- public function stop (bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): array
258
+ public function stop (bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): RawCodeCoverageData
259
259
{
260
260
if (!\is_array ($ linesToBeCovered ) && $ linesToBeCovered !== false ) {
261
261
throw InvalidArgumentException::create (
@@ -285,7 +285,7 @@ public function stop(bool $append = true, $linesToBeCovered = [], array $linesTo
285
285
* @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException
286
286
* @throws RuntimeException
287
287
*/
288
- public function append (array $ data , $ id = null , bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): void
288
+ public function append (RawCodeCoverageData $ rawData , $ id = null , bool $ append = true , $ linesToBeCovered = [], array $ linesToBeUsed = [], bool $ ignoreForceCoversAnnotation = false ): void
289
289
{
290
290
if ($ id === null ) {
291
291
$ id = $ this ->currentId ;
@@ -295,24 +295,24 @@ public function append(array $data, $id = null, bool $append = true, $linesToBeC
295
295
throw new RuntimeException ;
296
296
}
297
297
298
- $ this ->applyWhitelistFilter ($ data );
299
- $ this ->applyIgnoredLinesFilter ($ data );
300
- $ this ->initializeFilesThatAreSeenTheFirstTime ($ data );
298
+ $ this ->applyWhitelistFilter ($ rawData );
299
+ $ this ->applyIgnoredLinesFilter ($ rawData );
300
+ $ this ->initializeFilesThatAreSeenTheFirstTime ($ rawData );
301
301
302
302
if (!$ append ) {
303
303
return ;
304
304
}
305
305
306
306
if ($ id !== 'UNCOVERED_FILES_FROM_WHITELIST ' ) {
307
307
$ this ->applyCoversAnnotationFilter (
308
- $ data ,
308
+ $ rawData ,
309
309
$ linesToBeCovered ,
310
310
$ linesToBeUsed ,
311
311
$ ignoreForceCoversAnnotation
312
312
);
313
313
}
314
314
315
- if (empty ($ data )) {
315
+ if (empty ($ rawData -> getLineData () )) {
316
316
return ;
317
317
}
318
318
@@ -339,7 +339,7 @@ public function append(array $data, $id = null, bool $append = true, $linesToBeC
339
339
340
340
$ this ->tests [$ id ] = ['size ' => $ size , 'status ' => $ status ];
341
341
342
- foreach ($ data as $ file => $ lines ) {
342
+ foreach ($ rawData -> getLineData () as $ file => $ lines ) {
343
343
if (!$ this ->filter ->isFile ($ file )) {
344
344
continue ;
345
345
}
@@ -499,15 +499,15 @@ private function getLinePriority($data, $line)
499
499
* @throws MissingCoversAnnotationException
500
500
* @throws UnintentionallyCoveredCodeException
501
501
*/
502
- private function applyCoversAnnotationFilter (array & $ data , $ linesToBeCovered , array $ linesToBeUsed , bool $ ignoreForceCoversAnnotation ): void
502
+ private function applyCoversAnnotationFilter (RawCodeCoverageData $ rawData , $ linesToBeCovered , array $ linesToBeUsed , bool $ ignoreForceCoversAnnotation ): void
503
503
{
504
504
if ($ linesToBeCovered === false ||
505
505
($ this ->forceCoversAnnotation && empty ($ linesToBeCovered ) && !$ ignoreForceCoversAnnotation )) {
506
506
if ($ this ->checkForMissingCoversAnnotation ) {
507
507
throw new MissingCoversAnnotationException ;
508
508
}
509
509
510
- $ data = [] ;
510
+ $ rawData -> clear () ;
511
511
512
512
return ;
513
513
}
@@ -519,49 +519,49 @@ private function applyCoversAnnotationFilter(array &$data, $linesToBeCovered, ar
519
519
if ($ this ->checkForUnintentionallyCoveredCode &&
520
520
(!$ this ->currentId instanceof TestCase ||
521
521
(!$ this ->currentId ->isMedium () && !$ this ->currentId ->isLarge ()))) {
522
- $ this ->performUnintentionallyCoveredCodeCheck ($ data , $ linesToBeCovered , $ linesToBeUsed );
522
+ $ this ->performUnintentionallyCoveredCodeCheck ($ rawData , $ linesToBeCovered , $ linesToBeUsed );
523
523
}
524
524
525
525
if ($ this ->checkForUnexecutedCoveredCode ) {
526
- $ this ->performUnexecutedCoveredCodeCheck ($ data , $ linesToBeCovered , $ linesToBeUsed );
526
+ $ this ->performUnexecutedCoveredCodeCheck ($ rawData , $ linesToBeCovered , $ linesToBeUsed );
527
527
}
528
528
529
- $ data = \array_intersect_key ($ data , $ linesToBeCovered );
529
+ $ rawLineData = $ rawData ->getLineData ();
530
+ $ filesWithNoCoverage = \array_diff_key ($ rawLineData , $ linesToBeCovered );
530
531
531
- foreach (\array_keys ($ data ) as $ filename ) {
532
- $ _linesToBeCovered = \array_flip ($ linesToBeCovered [$ filename ]);
533
- $ data [$ filename ] = \array_intersect_key ($ data [$ filename ], $ _linesToBeCovered );
532
+ foreach (\array_keys ($ filesWithNoCoverage ) as $ fileWithNoCoverage ) {
533
+ $ rawData ->removeCoverageDataForFile ($ fileWithNoCoverage );
534
+ }
535
+
536
+ if (\is_array ($ linesToBeCovered )) {
537
+ foreach ($ linesToBeCovered as $ fileToBeCovered => $ includedLines ) {
538
+ $ rawData ->keepCoverageDataOnlyForLines ($ fileToBeCovered , $ includedLines );
539
+ }
534
540
}
535
541
}
536
542
537
- private function applyWhitelistFilter (array & $ data ): void
543
+ private function applyWhitelistFilter (RawCodeCoverageData $ data ): void
538
544
{
539
- foreach (\array_keys ($ data ) as $ filename ) {
545
+ foreach (\array_keys ($ data-> getLineData () ) as $ filename ) {
540
546
if ($ this ->filter ->isFiltered ($ filename )) {
541
- unset( $ data[ $ filename] );
547
+ $ data-> removeCoverageDataForFile ( $ filename );
542
548
}
543
549
}
544
550
}
545
551
546
552
/**
547
553
* @throws \SebastianBergmann\CodeCoverage\InvalidArgumentException
548
554
*/
549
- private function applyIgnoredLinesFilter (array & $ data ): void
555
+ private function applyIgnoredLinesFilter (RawCodeCoverageData $ data ): void
550
556
{
551
- foreach (\array_keys ($ data ) as $ filename ) {
552
- if (!$ this ->filter ->isFile ($ filename )) {
553
- continue ;
554
- }
555
-
556
- foreach ($ this ->getLinesToBeIgnored ($ filename ) as $ line ) {
557
- unset($ data [$ filename ][$ line ]);
558
- }
557
+ foreach (\array_keys ($ data ->getLineData ()) as $ filename ) {
558
+ $ data ->removeCoverageDataForLines ($ filename , $ this ->getLinesToBeIgnored ($ filename ));
559
559
}
560
560
}
561
561
562
- private function initializeFilesThatAreSeenTheFirstTime (array $ data ): void
562
+ private function initializeFilesThatAreSeenTheFirstTime (RawCodeCoverageData $ data ): void
563
563
{
564
- foreach ($ data as $ file => $ lines ) {
564
+ foreach ($ data-> getLineData () as $ file => $ lines ) {
565
565
if (!isset ($ this ->data [$ file ]) && $ this ->filter ->isFile ($ file )) {
566
566
$ this ->data [$ file ] = [];
567
567
@@ -602,7 +602,7 @@ private function addUncoveredFilesFromWhitelist(): void
602
602
}
603
603
}
604
604
605
- $ this ->append ($ data , 'UNCOVERED_FILES_FROM_WHITELIST ' );
605
+ $ this ->append (new RawCodeCoverageData ( $ data) , 'UNCOVERED_FILES_FROM_WHITELIST ' );
606
606
}
607
607
608
608
private function getLinesToBeIgnored (string $ fileName ): array
@@ -793,7 +793,7 @@ private function getLinesToBeIgnoredInner(string $fileName): array
793
793
* @throws \ReflectionException
794
794
* @throws UnintentionallyCoveredCodeException
795
795
*/
796
- private function performUnintentionallyCoveredCodeCheck (array & $ data , array $ linesToBeCovered , array $ linesToBeUsed ): void
796
+ private function performUnintentionallyCoveredCodeCheck (RawCodeCoverageData $ data , array $ linesToBeCovered , array $ linesToBeUsed ): void
797
797
{
798
798
$ allowedLines = $ this ->getAllowedLines (
799
799
$ linesToBeCovered ,
@@ -802,7 +802,7 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
802
802
803
803
$ unintentionallyCoveredUnits = [];
804
804
805
- foreach ($ data as $ file => $ _data ) {
805
+ foreach ($ data-> getLineData () as $ file => $ _data ) {
806
806
foreach ($ _data as $ line => $ flag ) {
807
807
if ($ flag === 1 && !isset ($ allowedLines [$ file ][$ line ])) {
808
808
$ unintentionallyCoveredUnits [] = $ this ->wizard ->lookup ($ file , $ line );
@@ -822,9 +822,9 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
822
822
/**
823
823
* @throws CoveredCodeNotExecutedException
824
824
*/
825
- private function performUnexecutedCoveredCodeCheck (array & $ data , array $ linesToBeCovered , array $ linesToBeUsed ): void
825
+ private function performUnexecutedCoveredCodeCheck (RawCodeCoverageData $ rawData , array $ linesToBeCovered , array $ linesToBeUsed ): void
826
826
{
827
- $ executedCodeUnits = $ this ->coverageToCodeUnits ($ data );
827
+ $ executedCodeUnits = $ this ->coverageToCodeUnits ($ rawData );
828
828
$ message = '' ;
829
829
830
830
foreach ($ this ->linesToCodeUnits ($ linesToBeCovered ) as $ codeUnit ) {
@@ -958,7 +958,7 @@ private function initializeData(): void
958
958
959
959
$ data = [];
960
960
961
- foreach ($ this ->driver ->stop () as $ file => $ fileCoverage ) {
961
+ foreach ($ this ->driver ->stop ()-> getLineData () as $ file => $ fileCoverage ) {
962
962
if ($ this ->filter ->isFiltered ($ file )) {
963
963
continue ;
964
964
}
@@ -972,15 +972,15 @@ private function initializeData(): void
972
972
$ data [$ file ] = $ fileCoverage ;
973
973
}
974
974
975
- $ this ->append ($ data , 'UNCOVERED_FILES_FROM_WHITELIST ' );
975
+ $ this ->append (new RawCodeCoverageData ( $ data) , 'UNCOVERED_FILES_FROM_WHITELIST ' );
976
976
}
977
977
}
978
978
979
- private function coverageToCodeUnits (array $ data ): array
979
+ private function coverageToCodeUnits (RawCodeCoverageData $ rawData ): array
980
980
{
981
981
$ codeUnits = [];
982
982
983
- foreach ($ data as $ filename => $ lines ) {
983
+ foreach ($ rawData -> getLineData () as $ filename => $ lines ) {
984
984
foreach ($ lines as $ line => $ flag ) {
985
985
if ($ flag === 1 ) {
986
986
$ codeUnits [] = $ this ->wizard ->lookup ($ filename , $ line );
0 commit comments