Skip to content

Commit 2b19d6e

Browse files
committed
Loop refactor. Early continue loop
1 parent 1630b24 commit 2b19d6e

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

src/CodeCoverage.php

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -611,49 +611,51 @@ private function applyIgnoredLinesFilter(array &$data)
611611
private function initializeFilesThatAreSeenTheFirstTime(array $data)
612612
{
613613
foreach ($data as $file => $fileData) {
614-
if ($this->filter->isFile($file) && !isset($this->data[$file])) {
615-
$this->data[$file] = ['lines' => []];
616-
617-
if ($this->pathCoverage) {
618-
$this->data[$file]['branches'] = [];
619-
$this->data[$file]['paths'] = [];
620-
621-
foreach ($fileData['functions'] as $functionName => $functionData) {
622-
$this->data[$file]['branches'][$functionName] = [];
623-
$this->data[$file]['paths'][$functionName] = [];
624-
625-
foreach ($functionData['branches'] as $index => $branch) {
626-
$this->data[$file]['branches'][$functionName][$index] = [
627-
'hit' => $branch['hit'],
628-
'line_start' => $branch['line_start'],
629-
'line_end' => $branch['line_end'],
630-
'tests' => []
631-
];
632-
}
614+
if (!$this->filter->isFile($file) || isset($this->data[$file])) {
615+
continue;
616+
}
633617

634-
foreach ($functionData['paths'] as $path) {
635-
$this->data[$file]['paths'][$functionName][] = $path;
636-
}
637-
}
638-
}
618+
$this->data[$file] = ['lines' => []];
639619

640-
foreach ($fileData['lines'] as $lineNumber => $flag) {
641-
if ($flag === PHP_CodeCoverage_Driver::LINE_NOT_EXECUTABLE) {
642-
$this->data[$file]['lines'][$lineNumber] = null;
643-
} else {
644-
$this->data[$file]['lines'][$lineNumber] = [
645-
'pathCovered' => false,
646-
'tests' => [],
620+
if ($this->pathCoverage) {
621+
$this->data[$file]['branches'] = [];
622+
$this->data[$file]['paths'] = [];
623+
624+
foreach ($fileData['functions'] as $functionName => $functionData) {
625+
$this->data[$file]['branches'][$functionName] = [];
626+
$this->data[$file]['paths'][$functionName] = [];
627+
628+
foreach ($functionData['branches'] as $index => $branch) {
629+
$this->data[$file]['branches'][$functionName][$index] = [
630+
'hit' => $branch['hit'],
631+
'line_start' => $branch['line_start'],
632+
'line_end' => $branch['line_end'],
633+
'tests' => []
647634
];
648635
}
636+
637+
foreach ($functionData['paths'] as $path) {
638+
$this->data[$file]['paths'][$functionName][] = $path;
639+
}
640+
}
641+
}
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+
];
649651
}
652+
}
650653

651-
foreach ($this->data[$file]['branches'] as $function) {
652-
foreach ($function as $branch) {
653-
for ($i = $branch['line_start']; $i < $branch['line_end']; $i++) {
654-
if (isset($this->data[$file]['lines'][$i])) {
655-
$this->data[$file]['lines'][$i]['pathCovered'] = (bool) $branch['hit'];
656-
}
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'];
657659
}
658660
}
659661
}

0 commit comments

Comments
 (0)