Skip to content

Commit

Permalink
Steer PHPstan for the EventFeed reading
Browse files Browse the repository at this point in the history
This is always going to be ugly as the event can have different shapes
even within the same EventFeedFormat, together with the minor changes
between formats.
  • Loading branch information
vmcj committed Feb 10, 2024
1 parent 6649877 commit 358684e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 30 deletions.
30 changes: 0 additions & 30 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,6 @@ parameters:
count: 1
path: webapp/src/FosRestBundle/FlattenExceptionHandler.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:addPendingEvent\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:compareOrCreateValues\\(\\) has parameter \\$extraDiff with no value type specified in iterable type array\\.$#"
count: 1
Expand All @@ -84,36 +79,11 @@ parameters:
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:getEventFeedFormat\\(\\) has parameter \\$event with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:import\\(\\) has parameter \\$eventsToSkip with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:importClarification\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:importEvent\\(\\) has parameter \\$event with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:importEvent\\(\\) has parameter \\$eventsToSKip with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:importFromCcsApi\\(\\) has parameter \\$eventsToSkip with no value type specified in iterable type array\\.$#"
count: 1
path: webapp/src/Service/ExternalContestSourceService.php

-
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:importFromContestArchive\\(\\) has parameter \\$eventsToSkip with no value type specified in iterable type array\\.$#"
count: 1
Expand Down
37 changes: 37 additions & 0 deletions webapp/src/Service/ExternalContestSourceService.php
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,9 @@ public function getLastReadEventId(): ?string
->getSingleScalarResult();
}

/**
* @param string[] $eventsToSkip
*/
public function import(bool $fromStart, array $eventsToSkip, ?callable $progressReporter = null): bool
{
// We need the verdicts to validate judgement-types.
Expand Down Expand Up @@ -290,6 +293,9 @@ protected function setLastEvent(?string $eventId): void
->execute();
}

/**
* @param string[] $eventsToSkip
*/
protected function importFromCcsApi(array $eventsToSkip, ?callable $progressReporter = null): bool
{
while (true) {
Expand Down Expand Up @@ -568,6 +574,17 @@ protected function loadContest(): void

/**
* Import the given event.
*
* @param array{token?: string, id: string, type: string, time: string, op?: string, end_of_updates?: bool,
* data?: array{run_time?: float, time?: string, contest_time?: string, ordinal?: int,
* id: string, judgement_id?: string, judgement_type_id: string|null,
* max_run_time?: float|null, start_time: string, start_contest_time?: string,
* end_time?: string|null, end_contest_time?: string|null, submission_id: string,
* output_compile_as_string: null, language_id?: string, externalid?: null,
* team_id: string, problem_id?: string, entry_point?: string|null, old_result?: null,
* files?: array{href: string}}|mixed[]
* } $event
* @param string[] $eventsToSkip
* @throws DBALException
* @throws NonUniqueResultException
* @throws TransportExceptionInterface
Expand Down Expand Up @@ -1776,6 +1793,15 @@ protected function processPendingEvents(string $type, string|int $id): void
}
}

/**
* @param array{run_time?: float, time?: string, contest_time?: string, ordinal?: int,
* id: string, judgement_id?: string, judgement_type_id: string|null,
* max_run_time?: float|null, start_time: string, start_contest_time?: string,
* end_time?: string|null, end_contest_time?: string|null, submission_id: string,
* output_compile_as_string: null, language_id?: string, externalid?: null,
* team_id: string, problem_id?: string, entry_point?: string|null, old_result?: null,
* files?: array{href: string}} $data
*/
protected function addPendingEvent(string $type, string|int $id, string $operation, string $entityType, ?string $eventId, array $data): void
{
// First, check if we already have pending events for this event.
Expand Down Expand Up @@ -1996,6 +2022,17 @@ protected function removeWarning(string $entityType, ?string $entityId, string $
}
}

/**
* @param array{token?: string, id: string, type: string, time: string, op?: string, end_of_updates?: bool,
* data?: array{run_time?: float, time?: string, contest_time?: string, ordinal?: int,
* id: string, judgement_id?: string, judgement_type_id: string|null,
* max_run_time?: float|null, start_time: string, start_contest_time?: string,
* end_time?: string|null, end_contest_time?: string|null, submission_id: string,
* output_compile_as_string: null, language_id?: string, externalid?: null,
* team_id: string, problem_id?: string, entry_point?: string|null, old_result?: null,
* files?: array{href: string}}|mixed[]
* } $event
*/
protected function getEventFeedFormat(array $event): EventFeedFormat
{
return match ($this->getApiVersion()) {
Expand Down

0 comments on commit 358684e

Please sign in to comment.