Skip to content

Commit a3da5c5

Browse files
vmcjnickygerritsen
andcommitted
Fix PHPStan issues for /src/Utils/Utils.php
After those fixes PHPStan should have more information so it can detect more issues. Co-authored-by: Nicky Gerritsen <[email protected]>
1 parent b1e4b0f commit a3da5c5

File tree

4 files changed

+19
-37
lines changed

4 files changed

+19
-37
lines changed

phpstan-baseline.neon

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,38 +1179,3 @@ parameters:
11791179
message: "#^Method App\\\\Utils\\\\Scoreboard\\\\Summary\\:\\:__construct\\(\\) has parameter \\$problems with no value type specified in iterable type array\\.$#"
11801180
count: 1
11811181
path: webapp/src/Utils/Scoreboard/Summary.php
1182-
1183-
-
1184-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:computeLcsDiff\\(\\) return type has no value type specified in iterable type array\\.$#"
1185-
count: 1
1186-
path: webapp/src/Utils/Utils.php
1187-
1188-
-
1189-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:getImageSize\\(\\) return type has no value type specified in iterable type array\\.$#"
1190-
count: 1
1191-
path: webapp/src/Utils/Utils.php
1192-
1193-
-
1194-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:parseHexColor\\(\\) return type has no value type specified in iterable type array\\.$#"
1195-
count: 1
1196-
path: webapp/src/Utils/Utils.php
1197-
1198-
-
1199-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:parseTsvLine\\(\\) return type has no value type specified in iterable type array\\.$#"
1200-
count: 1
1201-
path: webapp/src/Utils/Utils.php
1202-
1203-
-
1204-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:reindex\\(\\) has parameter \\$array with no value type specified in iterable type array\\.$#"
1205-
count: 1
1206-
path: webapp/src/Utils/Utils.php
1207-
1208-
-
1209-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:reindex\\(\\) return type has no value type specified in iterable type array\\.$#"
1210-
count: 1
1211-
path: webapp/src/Utils/Utils.php
1212-
1213-
-
1214-
message: "#^Method App\\\\Utils\\\\Utils\\:\\:rgbToHex\\(\\) has parameter \\$color with no value type specified in iterable type array\\.$#"
1215-
count: 1
1216-
path: webapp/src/Utils/Utils.php

webapp/src/Controller/Jury/ContestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ public function indexAction(Request $request): Response
199199
->groupBy('i.contest')
200200
->getQuery()
201201
->getResult();
202-
$removedIntervals = Utils::reindex($removedIntervals, static fn($data) => $data['cid']);
202+
$removedIntervals = Utils::reindex($removedIntervals, static fn(array $data): int => $data['cid']);
203203
} else {
204204
$removedIntervals = [];
205205
}

webapp/src/Utils/Utils.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,8 @@ public static function convertToColor(string $hex): ?string
321321

322322
/**
323323
* Parse a hex color into it's three RGB values.
324+
*
325+
* @return array{int, int, int}
324326
*/
325327
public static function parseHexColor(string $hex): array
326328
{
@@ -345,6 +347,8 @@ public static function componentToHex(int $component): string
345347

346348
/**
347349
* Convert an RGB triple into a CSS hex color.
350+
*
351+
* @param array{int, int, int} $color
348352
*/
349353
public static function rgbToHex(array $color): string
350354
{
@@ -506,6 +510,8 @@ public static function cutString(string $str, int $size): string
506510

507511
/**
508512
* Compute the LCS diff of two lines.
513+
*
514+
* @return array{bool, string}
509515
*/
510516
public static function computeLcsDiff(string $line1, string $line2): array
511517
{
@@ -686,6 +692,8 @@ public static function getImageThumb(string $image, int $thumbMaxSize, string $t
686692
* This method supports PNG, JPG, BMP, GIF and SVG files.
687693
*
688694
* Returns an array with three items: the width, height and ratio between width and height.
695+
*
696+
* @return array{int, int, float}
689697
*/
690698
public static function getImageSize(string $filename): array
691699
{
@@ -857,6 +865,8 @@ public static function toTsvField(string $field) : string
857865

858866
/**
859867
* Split a line from a Tab Separated Values file into fields.
868+
*
869+
* @return string[]
860870
*/
861871
public static function parseTsvLine(string $line): array
862872
{
@@ -865,6 +875,13 @@ public static function parseTsvLine(string $line): array
865875

866876
/**
867877
* Reindex the given array by applying the callback to each item.
878+
*
879+
* @template TKey of array-key
880+
* @template UKey of array-key
881+
* @template V
882+
* @param array<TKey, V> $array
883+
* @param callable(V, TKey): UKey $callback
884+
* @return array<UKey, V>
868885
*/
869886
public static function reindex(array $array, callable $callback): array
870887
{

webapp/tests/Unit/Utils/UtilsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ public function testReindex(): void
940940
{
941941
$input = [1, 2, 3];
942942
$expectedOutput = [2 => 1, 4 => 2, 6 => 3];
943-
$doubled = static fn($item) => $item * 2;
943+
$doubled = static fn(int $item): int => $item * 2;
944944
self::assertEquals($expectedOutput, Utils::reindex($input, $doubled));
945945
}
946946

0 commit comments

Comments
 (0)