Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/Node/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

use function array_filter;
use function count;
use function range;
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\StaticAnalysis\AnalysisResult;
use SebastianBergmann\CodeCoverage\StaticAnalysis\Class_;
Expand Down Expand Up @@ -372,15 +371,15 @@ public function numberOfTestedFunctions(): int
*/
private function calculateStatistics(array $classes, array $traits, array $functions): void
{
foreach (range(1, $this->linesOfCode->linesOfCode()) as $lineNumber) {
for ($lineNumber = 1; $lineNumber <= $this->linesOfCode->linesOfCode(); $lineNumber++) {
$this->codeUnitsByLine[$lineNumber] = [];
}

$this->processClasses($classes);
$this->processTraits($traits);
$this->processFunctions($functions);

foreach (range(1, $this->linesOfCode->linesOfCode()) as $lineNumber) {
for ($lineNumber = 1; $lineNumber <= $this->linesOfCode->linesOfCode(); $lineNumber++) {
if (isset($this->lineCoverageData[$lineNumber])) {
foreach ($this->codeUnitsByLine[$lineNumber] as &$codeUnit) {
$codeUnit['executableLines']++;
Expand Down Expand Up @@ -511,7 +510,7 @@ private function processClasses(array $classes): void
$this->numExecutablePaths += $methodData['executablePaths'];
$this->numExecutedPaths += $methodData['executedPaths'];

foreach (range($method->startLine(), $method->endLine()) as $lineNumber) {
for ($lineNumber = $method->startLine(); $lineNumber <= $method->endLine(); $lineNumber++) {
$this->codeUnitsByLine[$lineNumber] = [
&$this->classes[$className],
&$this->classes[$className]['methods'][$methodName],
Expand Down Expand Up @@ -560,7 +559,7 @@ private function processTraits(array $traits): void
$this->numExecutablePaths += $methodData['executablePaths'];
$this->numExecutedPaths += $methodData['executedPaths'];

foreach (range($method->startLine(), $method->endLine()) as $lineNumber) {
for ($lineNumber = $method->startLine(); $lineNumber <= $method->endLine(); $lineNumber++) {
$this->codeUnitsByLine[$lineNumber] = [
&$this->traits[$traitName],
&$this->traits[$traitName]['methods'][$methodName],
Expand Down Expand Up @@ -596,7 +595,7 @@ private function processFunctions(array $functions): void
'link' => $link . $function->startLine(),
];

foreach (range($function->startLine(), $function->endLine()) as $lineNumber) {
for ($lineNumber = $function->startLine(); $lineNumber <= $function->endLine(); $lineNumber++) {
$this->codeUnitsByLine[$lineNumber] = [&$this->functions[$functionName]];
}

Expand Down
3 changes: 1 addition & 2 deletions src/Report/Clover.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use function is_string;
use function ksort;
use function max;
use function range;
use function time;
use DOMDocument;
use SebastianBergmann\CodeCoverage\CodeCoverage;
Expand Down Expand Up @@ -95,7 +94,7 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string

$methodCount = 0;

foreach (range($method['startLine'], $method['endLine']) as $line) {
for ($line = $method['startLine']; $line <= $method['endLine']; $line++) {
if (isset($coverageData[$line])) {
$methodCount = max($methodCount, count($coverageData[$line]));
}
Expand Down
5 changes: 2 additions & 3 deletions src/Report/Cobertura.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
use function basename;
use function count;
use function preg_match;
use function range;
use function str_replace;
use function time;
use DOMImplementation;
Expand Down Expand Up @@ -170,7 +169,7 @@ public function process(CodeCoverage $coverage, ?string $target = null): string

$methodElement->appendChild($methodLinesElement);

foreach (range($method['startLine'], $method['endLine']) as $line) {
for ($line = $method['startLine']; $line <= $method['endLine']; $line++) {
if (!isset($coverageData[$line])) {
continue;
}
Expand Down Expand Up @@ -251,7 +250,7 @@ public function process(CodeCoverage $coverage, ?string $target = null): string

$methodElement->appendChild($methodLinesElement);

foreach (range($function['startLine'], $function['endLine']) as $line) {
for ($line = $function['startLine']; $line <= $function['endLine']; $line++) {
if (!isset($coverageData[$line])) {
continue;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Report/Html/Renderer/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ private function renderSourceWithBranchCoverage(FileNode $node): string

foreach ($functionCoverageData as $method) {
foreach ($method['branches'] as $branch) {
foreach (range($branch['line_start'], $branch['line_end']) as $line) {
for ($line = $branch['line_start']; $line <= $branch['line_end']; $line++) {
if (!isset($lineData[$line])) { // blank line at end of file is sometimes included here
continue;
}
Expand Down Expand Up @@ -696,7 +696,7 @@ private function renderSourceWithPathCoverage(FileNode $node): string
foreach ($functionCoverageData as $method) {
foreach ($method['paths'] as $pathId => $path) {
foreach ($path['path'] as $branchTaken) {
foreach (range($method['branches'][$branchTaken]['line_start'], $method['branches'][$branchTaken]['line_end']) as $line) {
for ($line = $method['branches'][$branchTaken]['line_start']; $line <= $method['branches'][$branchTaken]['line_end']; $line++) {
if (!isset($lineData[$line])) {
continue;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Report/OpenClover.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use function is_string;
use function ksort;
use function max;
use function range;
use function str_replace;
use function time;
use DOMDocument;
Expand Down Expand Up @@ -99,7 +98,7 @@ public function process(CodeCoverage $coverage, ?string $target = null, ?string

$methodCount = 0;

foreach (range($method['startLine'], $method['endLine']) as $line) {
for ($line = $method['startLine']; $line <= $method['endLine']; $line++) {
if (isset($coverageData[$line])) {
$methodCount = max($methodCount, count($coverageData[$line]));
}
Expand Down
11 changes: 5 additions & 6 deletions src/StaticAnalysis/Visitor/ExecutableLinesFindingVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
use function max;
use function preg_match;
use function preg_quote;
use function range;
use function reset;
use function sprintf;
use PhpParser\Node;
Expand Down Expand Up @@ -75,7 +74,7 @@ public function enterNode(Node $node): null
$endLine = $node->getEndLine() - 1;

if ($startLine <= $endLine) {
foreach (range($startLine, $endLine) as $line) {
for ($line = $startLine; $line <= $endLine; $line++) {
unset($this->executableLinesGroupedByBranch[$line]);
}
}
Expand All @@ -84,7 +83,7 @@ public function enterNode(Node $node): null
}

if ($node instanceof Node\Stmt\Interface_) {
foreach (range($node->getStartLine(), $node->getEndLine()) as $line) {
for ($line = $node->getStartLine(); $line <= $node->getEndLine(); $line++) {
$this->unsets[$line] = true;
}

Expand Down Expand Up @@ -144,7 +143,7 @@ public function enterNode(Node $node): null
$unsets = [];

foreach ($node->getParams() as $param) {
foreach (range($param->getStartLine(), $param->getEndLine()) as $line) {
for ($line = $param->getStartLine(); $line <= $param->getEndLine(); $line++) {
$unsets[$line] = true;
}
}
Expand All @@ -162,7 +161,7 @@ public function enterNode(Node $node): null
continue;
}

foreach (range($stmt->getStartLine(), $stmt->getEndLine()) as $line) {
for ($line = $stmt->getStartLine(); $line <= $stmt->getEndLine(); $line++) {
unset($this->executableLinesGroupedByBranch[$line]);

if (
Expand Down Expand Up @@ -395,7 +394,7 @@ public function executableLinesGroupedByBranch(): array

private function setLineBranch(int $start, int $end, int $branch): void
{
foreach (range($start, $end) as $line) {
for ($line = $start; $line <= $end; $line++) {
$this->executableLinesGroupedByBranch[$line] = $branch;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Target/MapBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function build(Filter $filter, FileAnalyser $analyser): array

$this->process($functions, $function->namespacedName(), $file, $function->startLine(), $function->endLine());

foreach (range($function->startLine(), $function->endLine()) as $line) {
for ($line = $function->startLine(); $line <= $function->endLine(); $line++) {
$reverseLookup[$file . ':' . $line] = $function->namespacedName();
}
}
Expand Down Expand Up @@ -202,7 +202,7 @@ private function processMethods(Class_|Trait_ $classOrTrait, string $file, array

$this->process($methods, $methodName, $file, $method->startLine(), $method->endLine());

foreach (range($method->startLine(), $method->endLine()) as $line) {
for ($line = $method->startLine(); $line <= $method->endLine(); $line++) {
$reverseLookup[$file . ':' . $line] = $methodName;
}
}
Expand All @@ -221,7 +221,7 @@ private function processNamespace(array &$data, string $namespace, string $file,
{
$parts = explode('\\', $namespace);

foreach (range(1, count($parts)) as $i) {
for ($i = 1; $i <= count($parts); $i++) {
$this->process($data, implode('\\', array_slice($parts, 0, $i)), $file, $startLine, $endLine);
}
}
Expand Down