Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less type casting with Utils::getBuildID() #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/api/nightly_crashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/ReleaseInsights/UtilsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down