Skip to content

Commit ac7d0be

Browse files
committed
Fix phpstan errors.
1 parent d4c4452 commit ac7d0be

File tree

3 files changed

+55
-34
lines changed

3 files changed

+55
-34
lines changed

webapp/src/Controller/API/JudgehostController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1049,7 +1049,7 @@ private function addSingleJudgingRun(
10491049

10501050
$judging->setResult($result);
10511051
if ($problem->isScoringProblem()) {
1052-
$judging->setScore($score);
1052+
$judging->setScore($score);
10531053
}
10541054

10551055
$hasNullResults = false;

webapp/src/Entity/TestcaseGroup.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,15 @@ class TestcaseGroup
4949
#[ORM\JoinColumn(name: 'parent_id', referencedColumnName: 'testcase_group_id', nullable: true, onDelete: 'SET NULL')]
5050
private ?self $parent = null;
5151

52+
/**
53+
* @var Collection<int, self>
54+
*/
5255
#[ORM\OneToMany(targetEntity: self::class, mappedBy: 'parent')]
5356
private Collection $children;
5457

58+
/**
59+
* @var Collection<int, Testcase>
60+
*/
5561
#[ORM\OneToMany(targetEntity: Testcase::class, mappedBy: 'testcaseGroup')]
5662
private Collection $testcases;
5763

@@ -143,11 +149,17 @@ public function setParent(?TestcaseGroup $parent): self
143149
return $this;
144150
}
145151

152+
/**
153+
* @return Collection<int, self>
154+
*/
146155
public function getChildren(): Collection
147156
{
148157
return $this->children;
149158
}
150159

160+
/**
161+
* @return Collection<int, Testcase>
162+
*/
151163
public function getTestcases(): Collection
152164
{
153165
return $this->testcases;

webapp/src/Service/SubmissionService.php

Lines changed: 42 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ public function __construct(
5959
protected readonly PaginatorInterface $paginator,
6060
) {}
6161

62+
/**
63+
* Returns a two-element array:
64+
* - The score for the testcase group, or null if not all results are ready.
65+
* - The result for the testcase group, or null if not all results are ready.
66+
* @return array{string|null, string|null}
67+
*/
6268
public static function maybeSetScoringResult(TestcaseGroup $testcaseGroup, Judging $judging): array
6369
{
6470
$allResultsReady = true;
@@ -139,43 +145,46 @@ public static function maybeSetScoringResult(TestcaseGroup $testcaseGroup, Judgi
139145
}
140146

141147
$testcaseAggregationType = $testcaseGroup->getAggregationType();
142-
if ($testcaseAggregationType === TestcaseAggregationType::SUM
143-
|| $testcaseAggregationType === TestcaseAggregationType::AVG) {
144-
$score = "0";
145-
foreach ($results as $result) {
146-
if ($result === null) {
147-
$allResultsReady = false;
148-
break;
149-
} else {
150-
$score = bcadd($score, $result, ScoreboardService::SCALE);
151-
}
152-
}
153-
if ($testcaseAggregationType === TestcaseAggregationType::AVG && count($results) > 0) {
154-
$score = bcdiv($score, (string)count($results), ScoreboardService::SCALE);
155-
}
156-
} elseif ($testcaseAggregationType === TestcaseAggregationType::MIN
157-
|| $testcaseAggregationType === TestcaseAggregationType::MAX) {
158-
$score = null;
159-
foreach ($results as $result) {
160-
if ($result === null) {
161-
$allResultsReady = false;
162-
break;
163-
} elseif ($score === null) {
164-
$score = $result;
165-
} else {
166-
if ($testcaseAggregationType === TestcaseAggregationType::MIN
167-
&& bccomp($result, $score, ScoreboardService::SCALE) < 0) {
168-
$score = $result;
148+
switch ($testcaseAggregationType) {
149+
case TestcaseAggregationType::SUM:
150+
case TestcaseAggregationType::AVG:
151+
$score = "0";
152+
foreach ($results as $result) {
153+
if ($result === null) {
154+
$allResultsReady = false;
155+
break;
156+
} else {
157+
$score = bcadd($score, $result, ScoreboardService::SCALE);
169158
}
170-
if ($testcaseAggregationType === TestcaseAggregationType::MAX
171-
&& bccomp($result, $score, ScoreboardService::SCALE) > 0) {
159+
}
160+
if ($testcaseAggregationType === TestcaseAggregationType::AVG && count($results) > 0) {
161+
$score = bcdiv($score, (string)count($results), ScoreboardService::SCALE);
162+
}
163+
break;
164+
case TestcaseAggregationType::MIN:
165+
case TestcaseAggregationType::MAX:
166+
$score = null;
167+
foreach ($results as $result) {
168+
if ($result === null) {
169+
$allResultsReady = false;
170+
break;
171+
} elseif ($score === null) {
172172
$score = $result;
173+
} else {
174+
if ($testcaseAggregationType === TestcaseAggregationType::MIN
175+
&& bccomp($result, $score, ScoreboardService::SCALE) < 0) {
176+
$score = $result;
177+
}
178+
if ($testcaseAggregationType === TestcaseAggregationType::MAX
179+
&& bccomp($result, $score, ScoreboardService::SCALE) > 0) {
180+
$score = $result;
181+
}
173182
}
174183
}
175-
}
176-
} else {
177-
throw new InvalidArgumentException(sprintf("Unknown testcase aggregation type '%s'.",
178-
$testcaseAggregationType->name));
184+
break;
185+
default:
186+
throw new InvalidArgumentException(sprintf("Unknown testcase aggregation type '%s'.",
187+
$testcaseAggregationType->name));
179188
}
180189

181190
if ($allResultsReady || (!$allCorrect && !$testcaseGroup->isOnRejectContinue())) {

0 commit comments

Comments
 (0)