From 358684e9cc2c69b67c3dba7b3084d437eebdf30a Mon Sep 17 00:00:00 2001 From: Michael Vasseur <14887731+vmcj@users.noreply.github.com> Date: Sat, 10 Feb 2024 00:19:09 +0100 Subject: [PATCH] Steer PHPstan for the EventFeed reading 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. --- phpstan-baseline.neon | 30 --------------- .../Service/ExternalContestSourceService.php | 37 +++++++++++++++++++ 2 files changed, 37 insertions(+), 30 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 73ebf7c76e..638efdc4a9 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -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 @@ -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 diff --git a/webapp/src/Service/ExternalContestSourceService.php b/webapp/src/Service/ExternalContestSourceService.php index ee58687aef..7e05a51bf3 100644 --- a/webapp/src/Service/ExternalContestSourceService.php +++ b/webapp/src/Service/ExternalContestSourceService.php @@ -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. @@ -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) { @@ -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 @@ -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. @@ -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()) {