Skip to content

Commit

Permalink
Fix code style, remove dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Oct 24, 2023
1 parent 8477a3f commit d4840d3
Show file tree
Hide file tree
Showing 28 changed files with 121 additions and 138 deletions.
59 changes: 29 additions & 30 deletions app/classes/Cache/Cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,36 +113,6 @@ public static function isActivated(): bool
}

return defined('CACHE_ENABLED') ? CACHE_ENABLED : self::$CACHE_ENABLED; // @codeCoverageIgnore

}

/**
* Check if cached data for a key is usable
*
* @param string $id UID for the data
* @param int $ttl Number of seconds for time to live
*
* @return bool True if valid data
* False if cached data is not usable
*/
private static function isValidKey(string $id, int $ttl): bool
{
$immutable = ($ttl === -1) ? true : false;

// No cache file
if (! file_exists(self::getKeyPath($id, $immutable))) {
return false;
}

// Cache is obsolete and was deleted
if (self::isObsoleteKey($id, $ttl)) {
self::deleteKey($id);

return false;
}

// All good, cache is valid
return true;
}

/**
Expand Down Expand Up @@ -203,6 +173,35 @@ public static function getCachePath(): string
return defined('CACHE_PATH') ? CACHE_PATH : sys_get_temp_dir() . '/';
}

/**
* Check if cached data for a key is usable
*
* @param string $id UID for the data
* @param int $ttl Number of seconds for time to live
*
* @return bool True if valid data
* False if cached data is not usable
*/
private static function isValidKey(string $id, int $ttl): bool
{
$immutable = ($ttl === -1) ? true : false;

// No cache file
if (! file_exists(self::getKeyPath($id, $immutable))) {
return false;
}

// Cache is obsolete and was deleted
if (self::isObsoleteKey($id, $ttl)) {
self::deleteKey($id);

return false;
}

// All good, cache is valid
return true;
}

/**
* Check if the data has not expired
*
Expand Down
7 changes: 2 additions & 5 deletions app/classes/ReleaseInsights/Bugzilla.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static function getBugListLink(array $bug_numbers): string
return 'https://bugzilla.mozilla.org/buglist.cgi?bug_id=' . implode('%2C', $bug_numbers);
}


/**
* Turn bug numbers in a string into Bugzilla links
*/
Expand All @@ -27,8 +26,7 @@ public static function linkify(string $text): ?string
return preg_replace_callback(
"/bug +\d+/i",
function (array $matches) {
return
'<a href="https://bugzilla.mozilla.org/'
return '<a href="https://bugzilla.mozilla.org/'
. trim(str_ireplace('bug', '', $matches[0]))
. '">'
. $matches[0]
Expand Down Expand Up @@ -69,12 +67,11 @@ public static function getBugsFromHgWeb(string $query, bool $detect_backouts = f
$get_bugs = function (string $str): array {
if (preg_match_all("/bug \d+/", $str, $matches)) {
$matches[0] = array_map(
fn(string $str) => str_replace('bug', '', $str),
fn (string $str) => str_replace('bug', '', $str),
$matches[0]
);

$matches[0] = array_map('trim', $matches[0]);

}
return $matches[0];
};
Expand Down
16 changes: 9 additions & 7 deletions app/classes/ReleaseInsights/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ class Data
public function __construct(
private string $pd_url = 'https://product-details.mozilla.org/1.0/',
public int $cache_duration = 900 // 15 minutes
)
{
) {
$this->release_owners = include DATA . 'release_owners.php';
$this->future_releases = include DATA . 'upcoming_releases.php';
}
Expand All @@ -34,7 +33,9 @@ public function getFutureReleases(): array
{
return array_filter(
$this->future_releases,
function (string $key) { return (int) $key > RELEASE; },
function (string $key) {
return (int) $key > RELEASE;
},
ARRAY_FILTER_USE_KEY
);
}
Expand All @@ -48,7 +49,9 @@ public function getESRReleases(): array
// Reduce to only ESR releases
$esr_releases = array_filter(
$esr_releases,
function (string $key) { return str_ends_with($key, 'esr'); },
function (string $key) {
return str_ends_with($key, 'esr');
},
ARRAY_FILTER_USE_KEY
);

Expand Down Expand Up @@ -77,7 +80,7 @@ public function getPastReleases(bool $dot_releases = true): array
asort($all_releases);

// Remove all minor ESR releases
$exclude_esr = function(string $version_number) {
$exclude_esr = function (string $version_number) {
// Those releases were not ESR releases despite the middle number
if (in_array($version_number, ['33.1', '33.1.1', '50.1.0'])) {
return true;
Expand Down Expand Up @@ -147,5 +150,4 @@ public function isTodayReleaseDay(): bool
{
return in_array(date('Y-m-d'), $this->getMajorReleases());
}

}
}
3 changes: 1 addition & 2 deletions app/classes/ReleaseInsights/Nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public function __construct(
// Testing url below
// string $AUS = 'https://stage.balrog.nonprod.cloudops.mozgcp.net/api/v1/',
public string $update_status = 'emergency_shutoff/Firefox/nightly',
)
{
) {
$this->version = Utils::getJson(
$this->pd . 'firefox_versions.json',
604800
Expand Down
1 change: 0 additions & 1 deletion app/classes/ReleaseInsights/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

class Performance
{

/**
* Utility function to return the memory used by a script
* and the time needed to compute the data.
Expand Down
35 changes: 10 additions & 25 deletions app/classes/ReleaseInsights/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,18 @@
namespace ReleaseInsights;

use DateTime;
use ReleaseInsights\{Data, Utils, Version};

enum Status
{
case Past;
case Current;
case Future;
}
use ReleaseInsights\{Data, Utils, Status, Version};

class Release
{
private string $version;

/** @var array<string> $no_planned_dot_releases */
public array $no_planned_dot_releases = ['108.0', '111.0', '115.0'];

/* @phpstan-ignore-next-line */
private Status $release_status;

private string $version;

public function __construct(string $version)
{
$this->version = Version::get($version);
Expand Down Expand Up @@ -51,20 +44,12 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
// Future release date object
$release = new DateTime($all_releases[$this->version] . ' 06:00 PST');

$beta_target = Version::decrement($this->version, 1);
$nightly_target = Version::decrement($this->version, 2);

if ($beta_target == '14.0') {
$beta_target = '14.0.1';
}

if ($nightly_target == '14.0') {
$nightly_target = '14.0.1';
}

// Previous release date object
$previous_release = new DateTime($all_releases[$beta_target] . ' 06:00 PST');

// Calculate 1st day of the nightly cycle
$nightly = new DateTime($all_releases[$nightly_target]);
$nightly->modify('-1 day');
Expand All @@ -77,7 +62,7 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
};

// Transform all the DateTime objects in the $schedule array into formated date strings
$date = function(string|object $day) use ($nightly): string {
$date = function (string|object $day) use ($nightly): string {
return is_object($day) ? $day->format('Y-m-d H:i:sP') : $nightly->modify($day)->format('Y-m-d H:i:sP');
};

Expand Down Expand Up @@ -116,11 +101,11 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
'soft_code_freeze' => $date('Thursday 08:00'),
'qa_pre_merge_done' => $date('Friday 14:00'),
'string_freeze' => $date('Friday'),
'merge_day' => match($this->version) {
'123.0' => $date('Monday +1 week'),
'135.0' => $date('Monday +2 week'),
default => $date('Monday'),
},
'merge_day' => match ($this->version) {
'123.0' => $date('Monday +1 week'),
'135.0' => $date('Monday +2 week'),
default => $date('Monday'),
},
'beta_1' => $date('Monday'),
'beta_2' => $date('Wednesday 13:00'),
'beta_3' => $date('Friday 13:00'),
Expand Down Expand Up @@ -204,4 +189,4 @@ public static function getNiceLabel(string $version, string $label, bool $short=

return $labels[$label];
}
}
}
9 changes: 3 additions & 6 deletions app/classes/ReleaseInsights/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ class Request
public ?string $query = null;
public bool $invalid_slashes = true;


public function __construct(string $path)
{
$request = parse_url($path);
Expand All @@ -29,9 +28,7 @@ public function __construct(string $path)
$this->invalid_slashes = false;
$this->path = explode('?', $path)[0];
} else {
/**
* We have a real path to route and clean up before usage
*/
// We have a real path to route and clean up before usage
$this->request = $path;

if (isset($request['path'])) {
Expand All @@ -53,8 +50,8 @@ public function __construct(string $path)
$this->invalid_slashes = false;
}
}
}
}
}
}
}

/**
Expand Down
12 changes: 12 additions & 0 deletions app/classes/ReleaseInsights/Status.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace ReleaseInsights;

enum Status
{
case Past;
case Current;
case Future;
}
11 changes: 5 additions & 6 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public static function getDate(string $format = 'Ymd'): string
public static function getBuildID(int $buildid): int
{
// Check that the string provided is correct
if (! self::isBuildID( (string) $buildid)) {
if (! self::isBuildID((string) $buildid)) {
return 20191014213051; // hardcoded fallback value
}

Expand Down Expand Up @@ -163,7 +163,7 @@ public static function getFile(string $url): string
// Local file
if (! isset(parse_url($url)['scheme'])) {
// Does it exist ?
if (! file_exists($url)){
if (! file_exists($url)) {
return '';
}

Expand All @@ -181,7 +181,7 @@ public static function getFile(string $url): string
// Request to Product-details failed (no answer from remote)
// We prefer to die here because this data is essential to the whole app.
if ($data === false && str_contains($url, 'product-details.mozilla.org')) {
die("Key external ressource $url currently not available, please try reloading the page.");
die("Key external ressource {$url} currently not available, please try reloading the page.");
}

// Request failed, let's return an empty string for now
Expand Down Expand Up @@ -329,9 +329,9 @@ public static function getMajorVersion(?string $version): ?int
return (int) explode('.', $version)[0];
}


/**
* Utility function to output Json data
*
* @param array<mixed> $data
*/
public static function renderJson(array $data): void
Expand All @@ -348,7 +348,6 @@ public static function renderJson(array $data): void

/**
* Utility function to get a visitor IP
*
*/
public static function getIP(): ?string
{
Expand All @@ -364,4 +363,4 @@ public static function getIP(): ?string

return null;
}
}
}
7 changes: 3 additions & 4 deletions app/classes/ReleaseInsights/Version.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

declare(strict_types=1);

namespace ReleaseInsights;

class Version
Expand Down Expand Up @@ -39,7 +39,7 @@ public static function get(?string $version = null): string
// Normalize version number to XX.y
return (string) number_format(abs((int) $version), 1, '.', '');
}

/**
* Get the major version number (91) from a string such as 91.0.1
*/
Expand All @@ -53,7 +53,6 @@ public static function getMajor(string $version): int
*/
public static function decrement(string $version, int $decrement): string
{

if ((int) $version - $decrement <= 1) {
return '1.0';
}
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/calendar_monthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@

declare(strict_types=1);

use ReleaseInsights\{Template, Data};
use ReleaseInsights\{Data, Template};

(new Template(
'calendar_monthly.html.twig',
[
'page_title' => 'General calendar of upcoming Firefox release milestones',
'css_page_id' => 'calendar_monthly',
'upcoming_releases' => (new Data)->getFutureReleases(),
'upcoming_releases' => (new Data())->getFutureReleases(),
'calendar' => require_once MODELS . 'calendar_monthly.php',
]
))->render();
Loading

0 comments on commit d4840d3

Please sign in to comment.