Skip to content

Commit 8e7a31b

Browse files
committed
Additional steering for PHPstan
Here we specify at the generic function and override with more specific fields if the function is overridden after inheritance. One improvement can be had with the awards where we should return always a list of awards instead of either an award or a list of awards.
1 parent 6b9a37d commit 8e7a31b

File tree

10 files changed

+33
-61
lines changed

10 files changed

+33
-61
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -180,51 +180,6 @@ parameters:
180180
count: 1
181181
path: webapp/src/Controller/API/SubmissionController.php
182182

183-
-
184-
message: "#^Method App\\\\Controller\\\\Jury\\\\ClarificationController\\:\\:getClarificationFormData\\(\\) return type has no value type specified in iterable type array\\.$#"
185-
count: 1
186-
path: webapp/src/Controller/Jury/ClarificationController.php
187-
188-
-
189-
message: "#^Method App\\\\Entity\\\\ExternalRelationshipEntityInterface\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
190-
count: 1
191-
path: webapp/src/Entity/ExternalRelationshipEntityInterface.php
192-
193-
-
194-
message: "#^Method App\\\\Entity\\\\ExternalSourceWarning\\:\\:getContent\\(\\) return type has no value type specified in iterable type array\\.$#"
195-
count: 1
196-
path: webapp/src/Entity/ExternalSourceWarning.php
197-
198-
-
199-
message: "#^Method App\\\\Entity\\\\ExternalSourceWarning\\:\\:setContent\\(\\) has parameter \\$content with no value type specified in iterable type array\\.$#"
200-
count: 1
201-
path: webapp/src/Entity/ExternalSourceWarning.php
202-
203-
-
204-
message: "#^Property App\\\\Entity\\\\ExternalSourceWarning\\:\\:\\$content type has no value type specified in iterable type array\\.$#"
205-
count: 1
206-
path: webapp/src/Entity/ExternalSourceWarning.php
207-
208-
-
209-
message: "#^Method App\\\\Entity\\\\Judging\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
210-
count: 1
211-
path: webapp/src/Entity/Judging.php
212-
213-
-
214-
message: "#^Method App\\\\Entity\\\\Submission\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
215-
count: 1
216-
path: webapp/src/Entity/Submission.php
217-
218-
-
219-
message: "#^Method App\\\\Entity\\\\Team\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
220-
count: 1
221-
path: webapp/src/Entity/Team.php
222-
223-
-
224-
message: "#^Method App\\\\Entity\\\\User\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
225-
count: 1
226-
path: webapp/src/Entity/User.php
227-
228183
-
229184
message: "#^Method App\\\\FosRestBundle\\\\FlattenExceptionHandler\\:\\:serializeToJson\\(\\) has parameter \\$type with no value type specified in iterable type array\\.$#"
230185
count: 1
@@ -250,21 +205,6 @@ parameters:
250205
count: 1
251206
path: webapp/src/Helpers/OrdinalArray.php
252207

253-
-
254-
message: "#^Method App\\\\Service\\\\AwardService\\:\\:getAwards\\(\\) return type has no value type specified in iterable type array\\.$#"
255-
count: 1
256-
path: webapp/src/Service/AwardService.php
257-
258-
-
259-
message: "#^Property App\\\\Service\\\\AwardService\\:\\:\\$awardCache type has no value type specified in iterable type array\\.$#"
260-
count: 1
261-
path: webapp/src/Service/AwardService.php
262-
263-
-
264-
message: "#^Method App\\\\Service\\\\BalloonService\\:\\:collectBalloonTable\\(\\) return type has no value type specified in iterable type array\\.$#"
265-
count: 1
266-
path: webapp/src/Service/BalloonService.php
267-
268208
-
269209
message: "#^Method App\\\\Service\\\\ExternalContestSourceService\\:\\:addOrUpdateWarning\\(\\) has parameter \\$content with no value type specified in iterable type array\\.$#"
270210
count: 1

webapp/src/Controller/Jury/ClarificationController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,9 @@ public function viewAction(int $id): Response
211211
);
212212
}
213213

214+
/**
215+
* @return array{teams: array<string|int, string>, subjects: array<string, array<string, string>>}
216+
*/
214217
protected function getClarificationFormData(?Team $team = null): array
215218
{
216219
$teamlist = [];

webapp/src/Entity/ExternalRelationshipEntityInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ interface ExternalRelationshipEntityInterface
1313
*
1414
* This method should return an array with as keys the JSON field names and as values the actual entity
1515
* objects that the SetExternalIdVisitor should check for applicable external IDs.
16+
*
17+
* @return array<string, Object|Object[]|null>
1618
*/
1719
public function getExternalRelationships(): array;
1820
}

webapp/src/Entity/ExternalSourceWarning.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ class ExternalSourceWarning
5454
#[ORM\Column(options: ['comment' => 'Hash of this warning. Unique within the source.'])]
5555
private string $hash;
5656

57+
/** @var array<string, mixed> $content */
5758
#[ORM\Column(
5859
type: 'json',
5960
options: ['comment' => 'JSON encoded content of the warning. Type-specific.']
@@ -135,11 +136,17 @@ public function setHash(string $hash): ExternalSourceWarning
135136
return $this;
136137
}
137138

139+
/**
140+
* @return array<string, mixed>
141+
*/
138142
public function getContent(): array
139143
{
140144
return $this->content;
141145
}
142146

147+
/**
148+
* @param array<string, mixed> $content
149+
*/
143150
public function setContent(array $content): ExternalSourceWarning
144151
{
145152
$this->content = $content;

webapp/src/Entity/Judging.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ public function getInternalError(): ?InternalError
444444
*
445445
* This method should return an array with as keys the JSON field names and as values the actual entity
446446
* objects that the SetExternalIdVisitor should check for applicable external ID's.
447+
*
448+
* @return array{submission_id: Submission}
447449
*/
448450
public function getExternalRelationships(): array
449451
{

webapp/src/Entity/Submission.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -444,6 +444,8 @@ public function getRejudging(): ?Rejudging
444444
*
445445
* This method should return an array with as keys the JSON field names and as values the actual entity
446446
* objects that the SetExternalIdVisitor should check for applicable external ID's.
447+
*
448+
* @return array{language_id: Language, problem_id: Problem, team_id: Team|null}
447449
*/
448450
public function getExternalRelationships(): array
449451
{

webapp/src/Entity/Team.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ public function canViewClarification(Clarification $clarification): bool
591591
}
592592

593593
/**
594-
* @inheritdoc
594+
* @return array{organization_id: TeamAffiliation|null, group_ids: TeamCategory[]}
595595
*/
596596
public function getExternalRelationships(): array
597597
{

webapp/src/Entity/User.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -500,6 +500,9 @@ public function getUserIdentifier(): string
500500
return $this->getUsername();
501501
}
502502

503+
/**
504+
* @return array{team_id: Team|null}
505+
*/
503506
public function getExternalRelationships(): array
504507
{
505508
return [

webapp/src/Service/AwardService.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
class AwardService
1010
{
11+
/** @var array<array{id: string, citation: string, team_ids: string[]}> $awardCache */
1112
protected array $awardCache = [];
1213

1314
public function __construct(protected readonly EventLogService $eventLogService)
@@ -114,6 +115,9 @@ protected function loadAwards(Contest $contest, Scoreboard $scoreboard): void
114115
$this->awardCache[$contest->getCid()] = $results;
115116
}
116117

118+
/**
119+
* @return array<array{id: string, citation: string, team_ids: string[]}>|array{id: string, citation: string, team_ids: string[]}|null
120+
*/
117121
public function getAwards(Contest $contest, Scoreboard $scoreboard, string $requestedType = null): ?array
118122
{
119123
if (!isset($this->awardCache[$contest->getCid()])) {

webapp/src/Service/BalloonService.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44

55
use App\Entity\Balloon;
66
use App\Entity\Contest;
7+
use App\Entity\ContestProblem;
78
use App\Entity\Judging;
89
use App\Entity\ScoreCache;
910
use App\Entity\Submission;
11+
use App\Entity\Team;
12+
use App\Entity\TeamAffiliation;
1013
use Doctrine\ORM\EntityManagerInterface;
1114
use Doctrine\ORM\NonUniqueResultException;
1215
use Doctrine\ORM\NoResultException;
@@ -75,6 +78,12 @@ public function updateBalloons(
7578
}
7679
}
7780

81+
/**
82+
* @return array<array{data: array{balloonid: int, time: string, problem: string, contestproblem: ContestProblem,
83+
* team: Team, teamid: int, location: string|null, affiliation: TeamAffiliation|null,
84+
* affiliationid: int, category: string, categoryid: int, total: array<string, ContestProblem>,
85+
* awards: string, done: bool}}>
86+
*/
7887
public function collectBalloonTable(Contest $contest, bool $todo = false): array
7988
{
8089
$em = $this->em;

0 commit comments

Comments
 (0)