88 * file that was distributed with this source code.
99 */
1010
11+ use SebastianBergmann \CodeUnitReverseLookup \Wizard ;
1112use SebastianBergmann \Environment \Runtime ;
1213
1314/**
@@ -27,6 +28,11 @@ class PHP_CodeCoverage
2728 */
2829 private $ filter ;
2930
31+ /**
32+ * @var Wizard
33+ */
34+ private $ wizard ;
35+
3036 /**
3137 * @var bool
3238 */
@@ -115,6 +121,8 @@ public function __construct(PHP_CodeCoverage_Driver $driver = null, PHP_CodeCove
115121
116122 $ this ->driver = $ driver ;
117123 $ this ->filter = $ filter ;
124+
125+ $ this ->wizard = new Wizard ;
118126 }
119127
120128 /**
@@ -887,23 +895,32 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
887895 $ linesToBeUsed
888896 );
889897
890- $ message = '' ;
898+ $ unintentionallyCoveredUnits = [] ;
891899
892900 foreach ($ data as $ file => $ _data ) {
893901 foreach ($ _data as $ line => $ flag ) {
894902 if ($ flag == 1 &&
895903 (!isset ($ allowedLines [$ file ]) ||
896904 !isset ($ allowedLines [$ file ][$ line ]))) {
897- $ message .= sprintf (
898- ' - %s:%d ' . PHP_EOL ,
899- $ file ,
900- $ line
901- );
905+ if ( $ this -> wizard -> lookup ( $ file , $ line )) {
906+ $ unintentionallyCoveredUnits [] = $ this -> wizard -> lookup ( $ file , $ line );
907+ } else {
908+ $ unintentionallyCoveredUnits [] = $ file . ' : ' . $ line;
909+ }
902910 }
903911 }
904912 }
905913
906- if (!empty ($ message )) {
914+ if (!empty ($ unintentionallyCoveredUnits )) {
915+ $ message = '' ;
916+
917+ $ unintentionallyCoveredUnits = array_unique ($ unintentionallyCoveredUnits );
918+ sort ($ unintentionallyCoveredUnits );
919+
920+ foreach ($ unintentionallyCoveredUnits as $ unit ) {
921+ $ message .= '- ' . $ unit . "\n" ;
922+ }
923+
907924 throw new PHP_CodeCoverage_UnintentionallyCoveredCodeException (
908925 $ message
909926 );
0 commit comments