Skip to content

Commit fe9f3b1

Browse files
Skip iteration when only one name needs to be mapped to a unit of code
1 parent f1f78ba commit fe9f3b1

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/Metadata/Api/CodeCoverage.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -247,14 +247,20 @@ private function mapToCodeUnits(CoversClass|CoversFunction|CoversMethod|UsesClas
247247
}
248248
}
249249

250-
$codeUnits = CodeUnitCollection::fromList();
251-
252250
try {
251+
if (count($names) === 1) {
252+
return $mapper->stringToCodeUnits($names[0]);
253+
}
254+
255+
$codeUnits = CodeUnitCollection::fromList();
256+
253257
foreach ($names as $name) {
254258
$codeUnits = $codeUnits->mergeWith(
255259
$mapper->stringToCodeUnits($name),
256260
);
257261
}
262+
263+
return $codeUnits;
258264
} catch (CodeUnitException $e) {
259265
if ($metadata->isCoversClass() || $metadata->isUsesClass()) {
260266
if (interface_exists($metadata->className())) {
@@ -276,7 +282,5 @@ private function mapToCodeUnits(CoversClass|CoversFunction|CoversMethod|UsesClas
276282
$e,
277283
);
278284
}
279-
280-
return $codeUnits;
281285
}
282286
}

0 commit comments

Comments
 (0)