From d6ca1c0fc1616641b105fe38e0febcdc9ea55412 Mon Sep 17 00:00:00 2001 From: Pascal Chevrel Date: Thu, 2 Feb 2023 22:25:59 +0100 Subject: [PATCH] Less type casting with Utils::getBuildID() --- app/classes/ReleaseInsights/Utils.php | 8 ++++---- app/models/api/nightly_crashes.php | 2 +- tests/Unit/ReleaseInsights/UtilsTest.php | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/classes/ReleaseInsights/Utils.php b/app/classes/ReleaseInsights/Utils.php index c1f08081..16d13592 100644 --- a/app/classes/ReleaseInsights/Utils.php +++ b/app/classes/ReleaseInsights/Utils.php @@ -79,18 +79,18 @@ public static function getDate(string $format = 'Ymd'): string /** * Get a Firefox BuildID and sanitize it * - * @param int $buildid Firefox Build ID in format 20191014213051 + * @param string $buildid Firefox Build ID in format 20191014213051 * * @return int sanitized buildID */ - public static function getBuildID(int $buildid): int + public static function getBuildID(string $buildid): int { // Check that the string provided is correct - if (! self::isBuildID( (string) $buildid)) { + if (! self::isBuildID($buildid)) { return 20191014213051; // hardcoded fallback value } - return $buildid; + return (int) $buildid; } public static function isBuildID(string $buildid): bool diff --git a/app/models/api/nightly_crashes.php b/app/models/api/nightly_crashes.php index e0073de4..c048e25d 100644 --- a/app/models/api/nightly_crashes.php +++ b/app/models/api/nightly_crashes.php @@ -4,7 +4,7 @@ use Cache\Cache; -$buildid = ReleaseInsights\Utils::getBuildID((int) ($_GET['buildid'] ?? 1)); +$buildid = ReleaseInsights\Utils::getBuildID($_GET['buildid'] ?? '1'); $cache_id = 'https://crash-stats.mozilla.com/api/SuperSearch/?build_id=' . (string) $buildid . '&_facets=signature&product=Firefox'; diff --git a/tests/Unit/ReleaseInsights/UtilsTest.php b/tests/Unit/ReleaseInsights/UtilsTest.php index 6f593337..0a4e36ff 100644 --- a/tests/Unit/ReleaseInsights/UtilsTest.php +++ b/tests/Unit/ReleaseInsights/UtilsTest.php @@ -26,10 +26,10 @@ test('Utils::getBuildID', function () { // Test fallback value - $this->assertEquals(20191014213051, U::getBuildID(20501229120000)); + $this->assertEquals(20191014213051, U::getBuildID('20501229120000')); // Test good value - $this->assertEquals(20201229120000, U::getBuildID(20201229120000)); + $this->assertEquals(20201229120000, U::getBuildID('20201229120000')); }); test('Utils::secureText', function ($input, $output) {