Skip to content

Commit ad08538

Browse files
committed
Fix PHPStan issues for /src/Entity/*
After those fixes PHPStan should have more information so it can detect more issues.
1 parent a3da5c5 commit ad08538

File tree

10 files changed

+47
-87
lines changed

10 files changed

+47
-87
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -325,21 +325,6 @@ parameters:
325325
count: 1
326326
path: webapp/src/DataFixtures/Test/RejudgingStatesFixture.php
327327

328-
-
329-
message: "#^Method App\\\\Entity\\\\Clarification\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
330-
count: 1
331-
path: webapp/src/Entity/Clarification.php
332-
333-
-
334-
message: "#^Method App\\\\Entity\\\\Contest\\:\\:getDataForJuryInterface\\(\\) return type has no value type specified in iterable type array\\.$#"
335-
count: 1
336-
path: webapp/src/Entity/Contest.php
337-
338-
-
339-
message: "#^Method App\\\\Entity\\\\Contest\\:\\:getState\\(\\) return type has no value type specified in iterable type array\\.$#"
340-
count: 1
341-
path: webapp/src/Entity/Contest.php
342-
343328
-
344329
message: "#^Method App\\\\Entity\\\\ExternalRelationshipEntityInterface\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
345330
count: 1
@@ -360,91 +345,26 @@ parameters:
360345
count: 1
361346
path: webapp/src/Entity/ExternalSourceWarning.php
362347

363-
-
364-
message: "#^Method App\\\\Entity\\\\InternalError\\:\\:getDisabled\\(\\) return type has no value type specified in iterable type array\\.$#"
365-
count: 1
366-
path: webapp/src/Entity/InternalError.php
367-
368-
-
369-
message: "#^Method App\\\\Entity\\\\InternalError\\:\\:setDisabled\\(\\) has parameter \\$disabled with no value type specified in iterable type array\\.$#"
370-
count: 1
371-
path: webapp/src/Entity/InternalError.php
372-
373-
-
374-
message: "#^Property App\\\\Entity\\\\InternalError\\:\\:\\$disabled type has no value type specified in iterable type array\\.$#"
375-
count: 1
376-
path: webapp/src/Entity/InternalError.php
377-
378348
-
379349
message: "#^Method App\\\\Entity\\\\Judging\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
380350
count: 1
381351
path: webapp/src/Entity/Judging.php
382352

383-
-
384-
message: "#^Method App\\\\Entity\\\\Judging\\:\\:getJudgehosts\\(\\) return type has no value type specified in iterable type array\\.$#"
385-
count: 1
386-
path: webapp/src/Entity/Judging.php
387-
388-
-
389-
message: "#^Method App\\\\Entity\\\\Language\\:\\:getExtensions\\(\\) return type has no value type specified in iterable type array\\.$#"
390-
count: 1
391-
path: webapp/src/Entity/Language.php
392-
393-
-
394-
message: "#^Method App\\\\Entity\\\\Language\\:\\:setExtensions\\(\\) has parameter \\$extensions with no value type specified in iterable type array\\.$#"
395-
count: 1
396-
path: webapp/src/Entity/Language.php
397-
398-
-
399-
message: "#^Method App\\\\Entity\\\\Submission\\:\\:getExpectedResults\\(\\) return type has no value type specified in iterable type array\\.$#"
400-
count: 1
401-
path: webapp/src/Entity/Submission.php
402-
403353
-
404354
message: "#^Method App\\\\Entity\\\\Submission\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
405355
count: 1
406356
path: webapp/src/Entity/Submission.php
407357

408-
-
409-
message: "#^Method App\\\\Entity\\\\Submission\\:\\:setExpectedResults\\(\\) has parameter \\$expectedResults with no value type specified in iterable type array\\.$#"
410-
count: 1
411-
path: webapp/src/Entity/Submission.php
412-
413-
-
414-
message: "#^Property App\\\\Entity\\\\Submission\\:\\:\\$expected_results type has no value type specified in iterable type array\\.$#"
415-
count: 1
416-
path: webapp/src/Entity/Submission.php
417-
418358
-
419359
message: "#^Method App\\\\Entity\\\\Team\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
420360
count: 1
421361
path: webapp/src/Entity/Team.php
422362

423-
-
424-
message: "#^Method App\\\\Entity\\\\Team\\:\\:getGroupIds\\(\\) return type has no value type specified in iterable type array\\.$#"
425-
count: 1
426-
path: webapp/src/Entity/Team.php
427-
428-
-
429-
message: "#^Method App\\\\Entity\\\\User\\:\\:__unserialize\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#"
430-
count: 1
431-
path: webapp/src/Entity/User.php
432-
433363
-
434364
message: "#^Method App\\\\Entity\\\\User\\:\\:getExternalRelationships\\(\\) return type has no value type specified in iterable type array\\.$#"
435365
count: 1
436366
path: webapp/src/Entity/User.php
437367

438-
-
439-
message: "#^Method App\\\\Entity\\\\User\\:\\:getRoleList\\(\\) return type has no value type specified in iterable type array\\.$#"
440-
count: 1
441-
path: webapp/src/Entity/User.php
442-
443-
-
444-
message: "#^Method App\\\\Entity\\\\User\\:\\:getUserRoles\\(\\) return type has no value type specified in iterable type array\\.$#"
445-
count: 1
446-
path: webapp/src/Entity/User.php
447-
448368
-
449369
message: "#^Method App\\\\FosRestBundle\\\\FlattenExceptionHandler\\:\\:convertToArray\\(\\) return type has no value type specified in iterable type array\\.$#"
450370
count: 1
@@ -1095,11 +1015,6 @@ parameters:
10951015
count: 1
10961016
path: webapp/src/Service/SubmissionService.php
10971017

1098-
-
1099-
message: "#^Method App\\\\Service\\\\SubmissionService\\:\\:getExpectedResults\\(\\) return type has no value type specified in iterable type array\\.$#"
1100-
count: 1
1101-
path: webapp/src/Service/SubmissionService.php
1102-
11031018
-
11041019
message: "#^Method App\\\\Service\\\\SubmissionService\\:\\:getFinalResult\\(\\) has parameter \\$resultsPrio with no value type specified in iterable type array\\.$#"
11051020
count: 1

webapp/src/Entity/Clarification.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,9 @@ public function getRecipientId(): ?int
335335
*
336336
* This method should return an array with as keys the JSON field names and as values the actual entity
337337
* objects that the SetExternalIdVisitor should check for applicable external ID's
338+
*
339+
* @return array{from_team_id: Team|null, to_team_id: Team|null,
340+
* problem_id: Problem|null, reply_to_id: Clarification|null}
338341
*/
339342
public function getExternalRelationships(): array
340343
{

webapp/src/Entity/Contest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,9 @@ public function getContestTime(float $wallTime): float
10221022
return $contestTime;
10231023
}
10241024

1025+
/**
1026+
* @return array<string, array{icon: string|null, label: string, time: string, show_button: bool}>
1027+
*/
10251028
public function getDataForJuryInterface(): array
10261029
{
10271030
$now = Utils::now();
@@ -1109,7 +1112,10 @@ public function getDataForJuryInterface(): array
11091112
return $result;
11101113
}
11111114

1112-
public function getState(): ?array
1115+
/**
1116+
* @return array<string, string|null>
1117+
*/
1118+
public function getState(): array
11131119
{
11141120
$time_or_null = function ($time, $extra_cond = true) {
11151121
if (!$extra_cond || $time === null || Utils::now() < $time) {

webapp/src/Entity/InternalError.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ class InternalError
4545
)]
4646
private string|float $time;
4747

48+
/**
49+
* @var array{kind: string, hostname?: string, execid?: string, probid: string, langid: string}
50+
*/
4851
#[ORM\Column(
4952
type: 'json',
5053
length: AbstractMySQLPlatform::LENGTH_LIMIT_TEXT,
@@ -122,12 +125,18 @@ public function getTime(): string|float
122125
return $this->time;
123126
}
124127

128+
/**
129+
* @param array{kind: string, hostname?: string, execid?: string, probid?: string, langid?: string} $disabled
130+
*/
125131
public function setDisabled(array $disabled): InternalError
126132
{
127133
$this->disabled = $disabled;
128134
return $this;
129135
}
130136

137+
/**
138+
* @return array{kind: string, hostname?: string, execid?: string, probid?: string, langid?: string}
139+
*/
131140
public function getDisabled(): array
132141
{
133142
return $this->disabled;

webapp/src/Entity/Judging.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,9 @@ public function isStillBusy(): bool
477477
return !empty($this->getResult()) && empty($this->getEndtime()) && !$this->isAborted();
478478
}
479479

480+
/**
481+
* @return string[]
482+
*/
480483
public function getJudgehosts(): array
481484
{
482485
$hostnames = [];

webapp/src/Entity/Language.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -291,12 +291,18 @@ public function getShortDescription(): string
291291
return $this->getName();
292292
}
293293

294+
/**
295+
* @param string[] $extensions
296+
*/
294297
public function setExtensions(array $extensions): Language
295298
{
296299
$this->extensions = $extensions;
297300
return $this;
298301
}
299302

303+
/**
304+
* @return string[]
305+
*/
300306
public function getExtensions(): array
301307
{
302308
return $this->extensions;

webapp/src/Entity/Submission.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ class Submission extends BaseApiEntity implements ExternalRelationshipEntityInte
7272
#[Serializer\Exclude]
7373
private bool $valid = true;
7474

75+
/** @var string[]|null $expected_results */
7576
#[ORM\Column(
7677
type: 'json',
7778
length: AbstractMySQLPlatform::LENGTH_LIMIT_TINYTEXT,
@@ -255,12 +256,18 @@ public function getValid(): bool
255256
return $this->valid;
256257
}
257258

259+
/**
260+
* @param string[] $expectedResults
261+
*/
258262
public function setExpectedResults(array $expectedResults): Submission
259263
{
260264
$this->expected_results = $expectedResults;
261265
return $this;
262266
}
263267

268+
/**
269+
* @return string[]
270+
*/
264271
public function getExpectedResults(): ?array
265272
{
266273
return $this->expected_results;

webapp/src/Entity/Team.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,9 @@ public function getUnreadClarifications(): Collection
543543
return $this->unread_clarifications;
544544
}
545545

546+
/**
547+
* @return array{int}|array{}
548+
*/
546549
#[Serializer\VirtualProperty]
547550
#[Serializer\Type('array<string>')]
548551
public function getGroupIds(): array

webapp/src/Entity/User.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,9 @@ public function __serialize(): array
157157
];
158158
}
159159

160+
/**
161+
* @param array{int|null, string|null, string|null} $data
162+
*/
160163
public function __unserialize(array $data): void
161164
{
162165
[
@@ -387,13 +390,18 @@ public function removeUserRole(Role $role): void
387390
$this->user_roles->removeElement($role);
388391
}
389392

393+
/**
394+
* @return Role[]
395+
*/
390396
public function getUserRoles(): array
391397
{
392398
return $this->user_roles->toArray();
393399
}
394400

395401
/**
396402
* Get the roles of this user as an array of strings
403+
*
404+
* @return array<string>
397405
*/
398406
#[Serializer\VirtualProperty]
399407
#[Serializer\SerializedName('roles')]

webapp/src/Service/SubmissionService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ public function submitSolution(
675675

676676
/**
677677
* Checks given source file for expected results string
678-
* @return array|false|null Array of expected results if found, false when multiple matches are found, or null otherwise.
678+
* @return string[]|false|null Array of expected results if found, false when multiple matches are found, or null otherwise.
679679
*/
680680
public static function getExpectedResults(string $source, array $resultsRemap): array|false|null
681681
{

0 commit comments

Comments
 (0)