Skip to content

Commit

Permalink
Set the exception codes
Browse files Browse the repository at this point in the history
  • Loading branch information
cedx committed May 24, 2024
1 parent 878ce38 commit e16a33e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static function parse(string $coverage): self {
case Token::endOfRecord: $report->sourceFiles[] = $sourceFile; break;

case Token::branchData:
if (count($data) < 4) throw new \InvalidArgumentException("Invalid branch data at line #$offset.");
if (count($data) < 4) throw new \InvalidArgumentException("Invalid branch data at line #$offset.", 422);
if ($sourceFile->branches) $sourceFile->branches->data[] = new BranchData(
blockNumber: (int) $data[1],
branchNumber: (int) $data[2],
Expand All @@ -67,20 +67,20 @@ static function parse(string $coverage): self {
break;

case Token::functionData:
if (count($data) < 2) throw new \InvalidArgumentException("Invalid function data at line #$offset.");
if (count($data) < 2) throw new \InvalidArgumentException("Invalid function data at line #$offset.", 422);
if ($sourceFile->functions) foreach ($sourceFile->functions->data as $item) if ($item->functionName == $data[1]) {
$item->executionCount = (int) $data[0];
break;
}
break;

case Token::functionName:
if (count($data) < 2) throw new \InvalidArgumentException("Invalid function name at line #$offset.");
if (count($data) < 2) throw new \InvalidArgumentException("Invalid function name at line #$offset.", 422);
if ($sourceFile->functions) $sourceFile->functions->data[] = new FunctionData(functionName: $data[1], lineNumber: (int) $data[0]);
break;

case Token::lineData:
if (($length = count($data)) < 2) throw new \InvalidArgumentException("Invalid line data at line #$offset.");
if (($length = count($data)) < 2) throw new \InvalidArgumentException("Invalid line data at line #$offset.", 422);
if ($sourceFile->lines) $sourceFile->lines->data[] = new LineData(
checksum: $length >= 3 ? $data[2] : "",
executionCount: (int) $data[1],
Expand All @@ -103,11 +103,11 @@ functions: new FunctionCoverage,
case Token::functionsHit: if ($sourceFile->functions) $sourceFile->functions->hit = (int) $data[0]; break;
case Token::linesFound: if ($sourceFile->lines) $sourceFile->lines->found = (int) $data[0]; break;
case Token::linesHit: if ($sourceFile->lines) $sourceFile->lines->hit = (int) $data[0]; break;
default: throw new \InvalidArgumentException("Unknown token at line #$offset.");
default: throw new \InvalidArgumentException("Unknown token at line #$offset.", 400);
}
}

if (!$report->sourceFiles) throw new \InvalidArgumentException("The coverage data is empty or invalid.");
if (!$report->sourceFiles) throw new \InvalidArgumentException("The coverage data is empty or invalid.", 400);
return $report;
}
}

0 comments on commit e16a33e

Please sign in to comment.