Skip to content

Commit d71bb6b

Browse files
committed
Optimize loop
1 parent 2b19d6e commit d71bb6b

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/CodeCoverage.php

+17-21
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,17 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data)
617617

618618
$this->data[$file] = ['lines' => []];
619619

620+
foreach ($fileData['lines'] as $lineNumber => $flag) {
621+
if ($flag === PHP_CodeCoverage_Driver::LINE_NOT_EXECUTABLE) {
622+
$this->data[$file]['lines'][$lineNumber] = null;
623+
} else {
624+
$this->data[$file]['lines'][$lineNumber] = [
625+
'pathCovered' => false,
626+
'tests' => [],
627+
];
628+
}
629+
}
630+
620631
if ($this->pathCoverage) {
621632
$this->data[$file]['branches'] = [];
622633
$this->data[$file]['paths'] = [];
@@ -632,34 +643,19 @@ private function initializeFilesThatAreSeenTheFirstTime(array $data)
632643
'line_end' => $branch['line_end'],
633644
'tests' => []
634645
];
646+
647+
for ($i = $branch['line_start']; $i < $branch['line_end']; $i++) {
648+
if (isset($this->data[$file]['lines'][$i])) {
649+
$this->data[$file]['lines'][$i]['pathCovered'] = (bool) $branch['hit'];
650+
}
651+
}
635652
}
636653

637654
foreach ($functionData['paths'] as $path) {
638655
$this->data[$file]['paths'][$functionName][] = $path;
639656
}
640657
}
641658
}
642-
643-
foreach ($fileData['lines'] as $lineNumber => $flag) {
644-
if ($flag === PHP_CodeCoverage_Driver::LINE_NOT_EXECUTABLE) {
645-
$this->data[$file]['lines'][$lineNumber] = null;
646-
} else {
647-
$this->data[$file]['lines'][$lineNumber] = [
648-
'pathCovered' => false,
649-
'tests' => [],
650-
];
651-
}
652-
}
653-
654-
foreach ($this->data[$file]['branches'] as $function) {
655-
foreach ($function as $branch) {
656-
for ($i = $branch['line_start']; $i < $branch['line_end']; $i++) {
657-
if (isset($this->data[$file]['lines'][$i])) {
658-
$this->data[$file]['lines'][$i]['pathCovered'] = (bool) $branch['hit'];
659-
}
660-
}
661-
}
662-
}
663659
}
664660
}
665661

0 commit comments

Comments
 (0)