From fcba469db7f8521ac5d370647650af37b52bb974 Mon Sep 17 00:00:00 2001 From: Michael Vasseur <14887731+vmcj@users.noreply.github.com> Date: Sun, 1 Sep 2024 00:10:41 +0200 Subject: [PATCH 1/2] Use the preg_match_all return to detect failures Even if we cannot match anything we would have had an array containing an empty array. That array indicates that nothing was matched. We should now fail when: - preg_match_all fails - preg_match_all returns it found 0 matches - the redundant case (as safeguard) when the array has 0 matches (cherry picked from commit 274d36ad2aba9ddc7669038b13262b875bede49b) --- webapp/src/Twig/TwigExtension.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webapp/src/Twig/TwigExtension.php b/webapp/src/Twig/TwigExtension.php index deff4a4f9c..3972b77ed0 100644 --- a/webapp/src/Twig/TwigExtension.php +++ b/webapp/src/Twig/TwigExtension.php @@ -1032,8 +1032,8 @@ public function hexColorToRGBA(string $text, float $opacity = 1): string if (is_null($col)) { return $text; } - preg_match_all("/[0-9A-Fa-f]{2}/", $col, $m); - if (!count($m)) { + $ret = preg_match_all("/[0-9A-Fa-f]{2}/", $col, $m); + if (!($ret && count($m[0]))) { return $text; } From a702c89fd62c4c0e2fee26b0e83aa0e82d65fc75 Mon Sep 17 00:00:00 2001 From: Michael Vasseur <14887731+vmcj@users.noreply.github.com> Date: Sun, 25 Aug 2024 11:51:47 +0200 Subject: [PATCH 2/2] Check for correct message The wrong state was picked in the past, PHPStan found this in an unrelated other issue. (cherry picked from commit bdd6ea39393af380687ef6efb59f2c87419ac462) --- webapp/tests/Unit/Controller/Jury/JuryMiscControllerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webapp/tests/Unit/Controller/Jury/JuryMiscControllerTest.php b/webapp/tests/Unit/Controller/Jury/JuryMiscControllerTest.php index 31e9b0bf89..bda8ae8583 100644 --- a/webapp/tests/Unit/Controller/Jury/JuryMiscControllerTest.php +++ b/webapp/tests/Unit/Controller/Jury/JuryMiscControllerTest.php @@ -91,7 +91,7 @@ public function testBalloonScoreboard(array $fixtures, bool $public, string $con $elements = ["3 tries",'Demo contest','Utrecht University']; } elseif (in_array($contestStage, ['preEnd','preUnfreeze'])) { $elements = ["0 + 4 tries","3 tries","2 + 1 tries",'Demo contest','Utrecht University']; - if ($contestStage === 'preFreeze') { + if ($contestStage === 'preUnfreeze') { $elements[] = 'contest over, waiting for results'; } } else {