Skip to content

Commit 6b9a37d

Browse files
committed
Annotate arrays for PHPstan to better analyze the code
Most is based on dumping the object, others on reading the code.
1 parent 0a72de8 commit 6b9a37d

File tree

4 files changed

+49
-86
lines changed

4 files changed

+49
-86
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -265,91 +265,6 @@ parameters:
265265
count: 1
266266
path: webapp/src/Service/BalloonService.php
267267

268-
-
269-
message: "#^Method App\\\\Service\\\\CheckConfigService\\:\\:checkAllExternalIdentifiers\\(\\) return type has no value type specified in iterable type array\\.$#"
270-
count: 1
271-
path: webapp/src/Service/CheckConfigService.php
272-
273-
-
274-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:apiRelativeUrl\\(\\) has parameter \\$params with no value type specified in iterable type array\\.$#"
275-
count: 1
276-
path: webapp/src/Service/DOMJudgeService.php
277-
278-
-
279-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getContestStats\\(\\) return type has no value type specified in iterable type array\\.$#"
280-
count: 1
281-
path: webapp/src/Service/DOMJudgeService.php
282-
283-
-
284-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getDocLinks\\(\\) return type has no value type specified in iterable type array\\.$#"
285-
count: 1
286-
path: webapp/src/Service/DOMJudgeService.php
287-
288-
-
289-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getProblemsForExecutable\\(\\) return type has no value type specified in iterable type array\\.$#"
290-
count: 1
291-
path: webapp/src/Service/DOMJudgeService.php
292-
293-
-
294-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getTwigDataForProblemsAction\\(\\) return type has no value type specified in iterable type array\\.$#"
295-
count: 1
296-
path: webapp/src/Service/DOMJudgeService.php
297-
298-
-
299-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getUnreadClarifications\\(\\) return type has no value type specified in iterable type array\\.$#"
300-
count: 1
301-
path: webapp/src/Service/DOMJudgeService.php
302-
303-
-
304-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:getUpdates\\(\\) return type has no value type specified in iterable type array\\.$#"
305-
count: 1
306-
path: webapp/src/Service/DOMJudgeService.php
307-
308-
-
309-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:internalApiRequest\\(\\) has parameter \\$queryOrPostData with no value type specified in iterable type array\\.$#"
310-
count: 1
311-
path: webapp/src/Service/DOMJudgeService.php
312-
313-
-
314-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:parseMetadata\\(\\) return type has no value type specified in iterable type array\\.$#"
315-
count: 1
316-
path: webapp/src/Service/DOMJudgeService.php
317-
318-
-
319-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:printFile\\(\\) return type has no value type specified in iterable type array\\.$#"
320-
count: 1
321-
path: webapp/src/Service/DOMJudgeService.php
322-
323-
-
324-
message: "#^Method App\\\\Service\\\\DOMJudgeService\\:\\:setInternalError\\(\\) has parameter \\$disabled with no value type specified in iterable type array\\.$#"
325-
count: 1
326-
path: webapp/src/Service/DOMJudgeService.php
327-
328-
-
329-
message: "#^Method App\\\\Service\\\\EventLogService\\:\\:hasAllDependentObjectEvents\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
330-
count: 1
331-
path: webapp/src/Service/EventLogService.php
332-
333-
-
334-
message: "#^Method App\\\\Service\\\\EventLogService\\:\\:insertEvent\\(\\) has parameter \\$content with no value type specified in iterable type array\\.$#"
335-
count: 1
336-
path: webapp/src/Service/EventLogService.php
337-
338-
-
339-
message: "#^Method App\\\\Service\\\\EventLogService\\:\\:insertEvents\\(\\) has parameter \\$contents with no value type specified in iterable type array\\.$#"
340-
count: 1
341-
path: webapp/src/Service/EventLogService.php
342-
343-
-
344-
message: "#^Method App\\\\Service\\\\EventLogService\\:\\:insertEvents\\(\\) has parameter \\$endpointIds with no value type specified in iterable type array\\.$#"
345-
count: 1
346-
path: webapp/src/Service/EventLogService.php
347-
348-
-
349-
message: "#^Property App\\\\Service\\\\EventLogService\\:\\:\\$entityToEndpoint type has no value type specified in iterable type array\\.$#"
350-
count: 1
351-
path: webapp/src/Service/EventLogService.php
352-
353268
-
354269
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:addOrUpdateWarning\\(\\) has parameter \\$content with no value type specified in iterable type array\\.$#"
355270
count: 1

webapp/src/Service/CheckConfigService.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -819,6 +819,9 @@ public function checkSelfRegistration(): array
819819
'desc' => $desc];
820820
}
821821

822+
/**
823+
* @return array<string, array{caption: string, result: string, desc: string, escape: bool}>
824+
*/
822825
public function checkAllExternalIdentifiers(): array
823826
{
824827
$this->stopwatch->start(__FUNCTION__);

webapp/src/Service/DOMJudgeService.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
use App\Entity\User;
3131
use App\Utils\FreezeData;
3232
use App\Utils\Utils;
33+
use DateTime;
3334
use Doctrine\ORM\EntityManagerInterface;
3435
use Doctrine\ORM\NonUniqueResultException;
3536
use Doctrine\ORM\NoResultException;
@@ -294,6 +295,9 @@ public function clearCookie(
294295
return $response;
295296
}
296297

298+
/**
299+
* @return array<array{'clarid': int, 'body': string}>
300+
*/
297301
public function getUnreadClarifications(): array
298302
{
299303
$user = $this->getUser();
@@ -315,6 +319,16 @@ public function getUnreadClarifications(): array
315319
return $unreadClarifications;
316320
}
317321

322+
/**
323+
* @return array{clarifications: array<array{clarid: int, body: string}>,
324+
* judgehosts: array<array{hostname: string, polltime: float}>,
325+
* rejudgings: array<array{rejudgingid: int, starttime: string, endtime: string|float}>,
326+
* internal_errors: array<array{errorid: int, description: string}>,
327+
* balloons: array<array{balloonid: int, name: string, location: string|null, pname: string}>,
328+
* shadow_difference_count: int,
329+
* external_contest_source_is_down: bool,
330+
* external_source_warning_count: int}
331+
*/
318332
public function getUpdates(): array
319333
{
320334
$contest = $this->getCurrentContest();
@@ -540,6 +554,9 @@ public function jsonEncode(mixed $data): string
540554

541555
/**
542556
* Dis- or re-enable what caused an internal error.
557+
*
558+
* @param array{kind: string, probid?: string, hostname?: string, langid?: string,
559+
* execid?: string, testcaseid?: string} $disabled
543560
*/
544561
public function setInternalError(array $disabled, ?Contest $contest, ?bool $enabled): void
545562
{
@@ -628,6 +645,7 @@ public function setInternalError(array $disabled, ?Contest $contest, ?bool $enab
628645
/**
629646
* Perform an internal API request to the given URL with the given data.
630647
*
648+
* @param array<string, string[]> $queryOrPostData
631649
* @param UploadedFile[] $files
632650
*
633651
* @return mixed|null
@@ -676,6 +694,9 @@ public function getDomjudgeWebappDir(): string
676694
return $this->params->get('domjudge.webappdir');
677695
}
678696

697+
/**
698+
* @return array{'name': string, 'link'?: string, 'icon'?: string}
699+
*/
679700
public function getDocLinks(): array
680701
{
681702
return $this->params->get('domjudge.doc_links');
@@ -715,6 +736,7 @@ public function openZipFile(string $filename): ZipArchive
715736
* @param string|null $teamname Teamname of the team this user belongs to, if any
716737
* @param string|null $teamid Teamid of the team this user belongs to, if any
717738
* @param string|null $location Location of the team, if any.
739+
* @return array{0: bool, 1: string}
718740
*/
719741
public function printFile(
720742
string $filename,
@@ -908,6 +930,7 @@ public function getAttachmentStreamedResponse(ContestProblem $contestProblem, in
908930
/**
909931
* @throws NoResultException
910932
* @throws NonUniqueResultException
933+
* @return array<string, int>
911934
*/
912935
public function getContestStats(Contest $contest): array
913936
{
@@ -944,6 +967,12 @@ public function getContestStats(Contest $contest): array
944967
}
945968

946969
/**
970+
* @return array{'problems': ContestProblem[], 'samples': string[], 'showLimits': bool,
971+
* 'defaultMemoryLimit': int, 'timeFactorDiffers': bool,
972+
* 'stats': array{'numBuckets': int, 'maxBucketSizeCorrect': int,
973+
* 'maxBucketSizeCorrect': int, 'maxBucketSizeIncorrect': int,
974+
* 'problems': array<array{'correct': array<array{'start': DateTime, 'end': DateTime, 'count': int}>,
975+
* 'incorrect': array<array{'start': DateTime, 'end': DateTime, 'count': int}>}>}}
947976
* @throws NonUniqueResultException
948977
*/
949978
public function getTwigDataForProblemsAction(
@@ -1311,6 +1340,9 @@ public function getImmutableRunExecutable(ContestProblem $problem): ImmutableExe
13111340
return $executable->getImmutableExecutable();
13121341
}
13131342

1343+
/**
1344+
* @return Problem[]
1345+
*/
13141346
private function getProblemsForExecutable(Executable $executable): array
13151347
{
13161348
$ret = array_merge($executable->getProblemsCompare()->toArray(),
@@ -1328,6 +1360,8 @@ private function getProblemsForExecutable(Executable $executable): array
13281360

13291361
/**
13301362
* Get the URL to a route relative to the API root
1363+
*
1364+
* @param array<string, string> $params
13311365
*/
13321366
public function apiRelativeUrl(string $route, array $params = []): string
13331367
{
@@ -1453,6 +1487,9 @@ public function loadTeam(string $idField, string $teamId, Contest $contest): Tea
14531487
return $team;
14541488
}
14551489

1490+
/**
1491+
* @return array<string, string>
1492+
*/
14561493
public function parseMetadata(string $raw_metadata): array
14571494
{
14581495
// TODO: Reduce duplication with judgedaemon code.

webapp/src/Service/EventLogService.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,10 @@ class EventLogService
137137
],
138138
];
139139

140-
// Entities to endpoints. Will be filled automatically except for special cases.
140+
/**
141+
* Entities to endpoints. Will be filled automatically except for special cases.
142+
* @var array<string, string> $entityToEndpoint
143+
*/
141144
protected array $entityToEndpoint = [
142145
// Special case for contest problems, as they should map to problems.
143146
ContestProblem::class => 'problems',
@@ -566,6 +569,8 @@ public function addMissingStateEvents(Contest $contest): void
566569
* This method will make sure that the events are all only inserted once,
567570
* even if called simultaneously from different processes.
568571
*
572+
* @param string[] $endpointIds
573+
* @param array<array<string, mixed>> $contents
569574
* @throws NonUniqueResultException
570575
*/
571576
protected function insertEvents(
@@ -631,6 +636,8 @@ protected function insertEvents(
631636
* This method will make sure that the event is only inserted once,
632637
* even if called simultaneously from different processes.
633638
*
639+
* @param array<string, string|null> $content
640+
*
634641
* @throws NonUniqueResultException
635642
*/
636643
protected function insertEvent(
@@ -723,6 +730,7 @@ public function initStaticEvents(Contest $contest): void
723730

724731
/**
725732
* Check if all events for dependent objects are present for the given type and data.
733+
* @param array<string, string|int|null|bool|string[]> $data
726734
* @return bool True if and only if all references are present
727735
*/
728736
protected function hasAllDependentObjectEvents(Contest $contest, string $type, array $data): bool

0 commit comments

Comments
 (0)