@@ -960,30 +960,24 @@ private function performUnintentionallyCoveredCodeCheck(array &$data, array $lin
960960 */
961961 private function performUnexecutedCoveredCodeCheck (array &$ data , array $ linesToBeCovered , array $ linesToBeUsed )
962962 {
963- $ expectedLines = $ this ->getAllowedLines (
964- $ linesToBeCovered ,
965- $ linesToBeUsed
966- );
967-
968- foreach ($ data as $ file => $ _data ) {
969- foreach (array_keys ($ _data ) as $ line ) {
970- if (!isset ($ expectedLines [$ file ][$ line ])) {
971- continue ;
972- }
973-
974- unset($ expectedLines [$ file ][$ line ]);
963+ $ executedCodeUnits = $ this ->coverageToCodeUnits ($ data );
964+ $ message = '' ;
965+
966+ foreach ($ this ->linesToCodeUnits ($ linesToBeCovered ) as $ codeUnit ) {
967+ if (!in_array ($ codeUnit , $ executedCodeUnits )) {
968+ $ message .= sprintf (
969+ '- %s is expected to be covered but was not executed ' . "\n" ,
970+ $ codeUnit
971+ );
975972 }
976973 }
977974
978- $ message = '' ;
979-
980- foreach ($ expectedLines as $ file => $ lines ) {
981- if (empty ($ lines )) {
982- continue ;
983- }
984-
985- foreach (array_keys ($ lines ) as $ line ) {
986- $ message .= sprintf ('- %s:%d ' . PHP_EOL , $ file , $ line );
975+ foreach ($ this ->linesToCodeUnits ($ linesToBeUsed ) as $ codeUnit ) {
976+ if (!in_array ($ codeUnit , $ executedCodeUnits )) {
977+ $ message .= sprintf (
978+ '- %s is expected to be used but was not executed ' . "\n" ,
979+ $ codeUnit
980+ );
987981 }
988982 }
989983
@@ -1124,4 +1118,42 @@ protected function initializeData()
11241118 $ this ->append ($ data , 'UNCOVERED_FILES_FROM_WHITELIST ' );
11251119 }
11261120 }
1121+
1122+ /**
1123+ * @param array $data
1124+ *
1125+ * @return array
1126+ */
1127+ private function coverageToCodeUnits (array $ data )
1128+ {
1129+ $ codeUnits = [];
1130+
1131+ foreach ($ data as $ filename => $ lines ) {
1132+ foreach ($ lines as $ line => $ flag ) {
1133+ if ($ flag == 1 ) {
1134+ $ codeUnits [] = $ this ->wizard ->lookup ($ filename , $ line );
1135+ }
1136+ }
1137+ }
1138+
1139+ return array_unique ($ codeUnits );
1140+ }
1141+
1142+ /**
1143+ * @param array $data
1144+ *
1145+ * @return array
1146+ */
1147+ private function linesToCodeUnits (array $ data )
1148+ {
1149+ $ codeUnits = [];
1150+
1151+ foreach ($ data as $ filename => $ lines ) {
1152+ foreach ($ lines as $ line ) {
1153+ $ codeUnits [] = $ this ->wizard ->lookup ($ filename , $ line );
1154+ }
1155+ }
1156+
1157+ return array_unique ($ codeUnits );
1158+ }
11271159}
0 commit comments