Skip to content

Commit d4840d3

Browse files
committed
Fix code style, remove dead code
1 parent 8477a3f commit d4840d3

28 files changed

+121
-138
lines changed

app/classes/Cache/Cache.php

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -113,36 +113,6 @@ public static function isActivated(): bool
113113
}
114114

115115
return defined('CACHE_ENABLED') ? CACHE_ENABLED : self::$CACHE_ENABLED; // @codeCoverageIgnore
116-
117-
}
118-
119-
/**
120-
* Check if cached data for a key is usable
121-
*
122-
* @param string $id UID for the data
123-
* @param int $ttl Number of seconds for time to live
124-
*
125-
* @return bool True if valid data
126-
* False if cached data is not usable
127-
*/
128-
private static function isValidKey(string $id, int $ttl): bool
129-
{
130-
$immutable = ($ttl === -1) ? true : false;
131-
132-
// No cache file
133-
if (! file_exists(self::getKeyPath($id, $immutable))) {
134-
return false;
135-
}
136-
137-
// Cache is obsolete and was deleted
138-
if (self::isObsoleteKey($id, $ttl)) {
139-
self::deleteKey($id);
140-
141-
return false;
142-
}
143-
144-
// All good, cache is valid
145-
return true;
146116
}
147117

148118
/**
@@ -203,6 +173,35 @@ public static function getCachePath(): string
203173
return defined('CACHE_PATH') ? CACHE_PATH : sys_get_temp_dir() . '/';
204174
}
205175

176+
/**
177+
* Check if cached data for a key is usable
178+
*
179+
* @param string $id UID for the data
180+
* @param int $ttl Number of seconds for time to live
181+
*
182+
* @return bool True if valid data
183+
* False if cached data is not usable
184+
*/
185+
private static function isValidKey(string $id, int $ttl): bool
186+
{
187+
$immutable = ($ttl === -1) ? true : false;
188+
189+
// No cache file
190+
if (! file_exists(self::getKeyPath($id, $immutable))) {
191+
return false;
192+
}
193+
194+
// Cache is obsolete and was deleted
195+
if (self::isObsoleteKey($id, $ttl)) {
196+
self::deleteKey($id);
197+
198+
return false;
199+
}
200+
201+
// All good, cache is valid
202+
return true;
203+
}
204+
206205
/**
207206
* Check if the data has not expired
208207
*

app/classes/ReleaseInsights/Bugzilla.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public static function getBugListLink(array $bug_numbers): string
1818
return 'https://bugzilla.mozilla.org/buglist.cgi?bug_id=' . implode('%2C', $bug_numbers);
1919
}
2020

21-
2221
/**
2322
* Turn bug numbers in a string into Bugzilla links
2423
*/
@@ -27,8 +26,7 @@ public static function linkify(string $text): ?string
2726
return preg_replace_callback(
2827
"/bug +\d+/i",
2928
function (array $matches) {
30-
return
31-
'<a href="https://bugzilla.mozilla.org/'
29+
return '<a href="https://bugzilla.mozilla.org/'
3230
. trim(str_ireplace('bug', '', $matches[0]))
3331
. '">'
3432
. $matches[0]
@@ -69,12 +67,11 @@ public static function getBugsFromHgWeb(string $query, bool $detect_backouts = f
6967
$get_bugs = function (string $str): array {
7068
if (preg_match_all("/bug \d+/", $str, $matches)) {
7169
$matches[0] = array_map(
72-
fn(string $str) => str_replace('bug', '', $str),
70+
fn (string $str) => str_replace('bug', '', $str),
7371
$matches[0]
7472
);
7573

7674
$matches[0] = array_map('trim', $matches[0]);
77-
7875
}
7976
return $matches[0];
8077
};

app/classes/ReleaseInsights/Data.php

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ class Data
1717
public function __construct(
1818
private string $pd_url = 'https://product-details.mozilla.org/1.0/',
1919
public int $cache_duration = 900 // 15 minutes
20-
)
21-
{
20+
) {
2221
$this->release_owners = include DATA . 'release_owners.php';
2322
$this->future_releases = include DATA . 'upcoming_releases.php';
2423
}
@@ -34,7 +33,9 @@ public function getFutureReleases(): array
3433
{
3534
return array_filter(
3635
$this->future_releases,
37-
function (string $key) { return (int) $key > RELEASE; },
36+
function (string $key) {
37+
return (int) $key > RELEASE;
38+
},
3839
ARRAY_FILTER_USE_KEY
3940
);
4041
}
@@ -48,7 +49,9 @@ public function getESRReleases(): array
4849
// Reduce to only ESR releases
4950
$esr_releases = array_filter(
5051
$esr_releases,
51-
function (string $key) { return str_ends_with($key, 'esr'); },
52+
function (string $key) {
53+
return str_ends_with($key, 'esr');
54+
},
5255
ARRAY_FILTER_USE_KEY
5356
);
5457

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

7982
// Remove all minor ESR releases
80-
$exclude_esr = function(string $version_number) {
83+
$exclude_esr = function (string $version_number) {
8184
// Those releases were not ESR releases despite the middle number
8285
if (in_array($version_number, ['33.1', '33.1.1', '50.1.0'])) {
8386
return true;
@@ -147,5 +150,4 @@ public function isTodayReleaseDay(): bool
147150
{
148151
return in_array(date('Y-m-d'), $this->getMajorReleases());
149152
}
150-
151-
}
153+
}

app/classes/ReleaseInsights/Nightly.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ public function __construct(
1818
// Testing url below
1919
// string $AUS = 'https://stage.balrog.nonprod.cloudops.mozgcp.net/api/v1/',
2020
public string $update_status = 'emergency_shutoff/Firefox/nightly',
21-
)
22-
{
21+
) {
2322
$this->version = Utils::getJson(
2423
$this->pd . 'firefox_versions.json',
2524
604800

app/classes/ReleaseInsights/Performance.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
class Performance
1010
{
11-
1211
/**
1312
* Utility function to return the memory used by a script
1413
* and the time needed to compute the data.

app/classes/ReleaseInsights/Release.php

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,25 +5,18 @@
55
namespace ReleaseInsights;
66

77
use DateTime;
8-
use ReleaseInsights\{Data, Utils, Version};
9-
10-
enum Status
11-
{
12-
case Past;
13-
case Current;
14-
case Future;
15-
}
8+
use ReleaseInsights\{Data, Utils, Status, Version};
169

1710
class Release
1811
{
19-
private string $version;
20-
2112
/** @var array<string> $no_planned_dot_releases */
2213
public array $no_planned_dot_releases = ['108.0', '111.0', '115.0'];
2314

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

18+
private string $version;
19+
2720
public function __construct(string $version)
2821
{
2922
$this->version = Version::get($version);
@@ -51,20 +44,12 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
5144
// Future release date object
5245
$release = new DateTime($all_releases[$this->version] . ' 06:00 PST');
5346

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

57-
if ($beta_target == '14.0') {
58-
$beta_target = '14.0.1';
59-
}
60-
6149
if ($nightly_target == '14.0') {
6250
$nightly_target = '14.0.1';
6351
}
6452

65-
// Previous release date object
66-
$previous_release = new DateTime($all_releases[$beta_target] . ' 06:00 PST');
67-
6853
// Calculate 1st day of the nightly cycle
6954
$nightly = new DateTime($all_releases[$nightly_target]);
7055
$nightly->modify('-1 day');
@@ -77,7 +62,7 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
7762
};
7863

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

@@ -116,11 +101,11 @@ public function getSchedule(string $pd_url = 'https://product-details.mozilla.or
116101
'soft_code_freeze' => $date('Thursday 08:00'),
117102
'qa_pre_merge_done' => $date('Friday 14:00'),
118103
'string_freeze' => $date('Friday'),
119-
'merge_day' => match($this->version) {
120-
'123.0' => $date('Monday +1 week'),
121-
'135.0' => $date('Monday +2 week'),
122-
default => $date('Monday'),
123-
},
104+
'merge_day' => match ($this->version) {
105+
'123.0' => $date('Monday +1 week'),
106+
'135.0' => $date('Monday +2 week'),
107+
default => $date('Monday'),
108+
},
124109
'beta_1' => $date('Monday'),
125110
'beta_2' => $date('Wednesday 13:00'),
126111
'beta_3' => $date('Friday 13:00'),
@@ -204,4 +189,4 @@ public static function getNiceLabel(string $version, string $label, bool $short=
204189

205190
return $labels[$label];
206191
}
207-
}
192+
}

app/classes/ReleaseInsights/Request.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ class Request
1111
public ?string $query = null;
1212
public bool $invalid_slashes = true;
1313

14-
1514
public function __construct(string $path)
1615
{
1716
$request = parse_url($path);
@@ -29,9 +28,7 @@ public function __construct(string $path)
2928
$this->invalid_slashes = false;
3029
$this->path = explode('?', $path)[0];
3130
} else {
32-
/**
33-
* We have a real path to route and clean up before usage
34-
*/
31+
// We have a real path to route and clean up before usage
3532
$this->request = $path;
3633

3734
if (isset($request['path'])) {
@@ -53,8 +50,8 @@ public function __construct(string $path)
5350
$this->invalid_slashes = false;
5451
}
5552
}
56-
}
57-
}
53+
}
54+
}
5855
}
5956

6057
/**
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace ReleaseInsights;
6+
7+
enum Status
8+
{
9+
case Past;
10+
case Current;
11+
case Future;
12+
}

app/classes/ReleaseInsights/Utils.php

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public static function getDate(string $format = 'Ymd'): string
106106
public static function getBuildID(int $buildid): int
107107
{
108108
// Check that the string provided is correct
109-
if (! self::isBuildID( (string) $buildid)) {
109+
if (! self::isBuildID((string) $buildid)) {
110110
return 20191014213051; // hardcoded fallback value
111111
}
112112

@@ -163,7 +163,7 @@ public static function getFile(string $url): string
163163
// Local file
164164
if (! isset(parse_url($url)['scheme'])) {
165165
// Does it exist ?
166-
if (! file_exists($url)){
166+
if (! file_exists($url)) {
167167
return '';
168168
}
169169

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

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

332-
333332
/**
334333
* Utility function to output Json data
334+
*
335335
* @param array<mixed> $data
336336
*/
337337
public static function renderJson(array $data): void
@@ -348,7 +348,6 @@ public static function renderJson(array $data): void
348348

349349
/**
350350
* Utility function to get a visitor IP
351-
*
352351
*/
353352
public static function getIP(): ?string
354353
{
@@ -364,4 +363,4 @@ public static function getIP(): ?string
364363

365364
return null;
366365
}
367-
}
366+
}

app/classes/ReleaseInsights/Version.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
2-
2+
33
declare(strict_types=1);
4-
4+
55
namespace ReleaseInsights;
66

77
class Version
@@ -39,7 +39,7 @@ public static function get(?string $version = null): string
3939
// Normalize version number to XX.y
4040
return (string) number_format(abs((int) $version), 1, '.', '');
4141
}
42-
42+
4343
/**
4444
* Get the major version number (91) from a string such as 91.0.1
4545
*/
@@ -53,7 +53,6 @@ public static function getMajor(string $version): int
5353
*/
5454
public static function decrement(string $version, int $decrement): string
5555
{
56-
5756
if ((int) $version - $decrement <= 1) {
5857
return '1.0';
5958
}

app/controllers/calendar_monthly.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
declare(strict_types=1);
44

5-
use ReleaseInsights\{Template, Data};
5+
use ReleaseInsights\{Data, Template};
66

77
(new Template(
88
'calendar_monthly.html.twig',
99
[
1010
'page_title' => 'General calendar of upcoming Firefox release milestones',
1111
'css_page_id' => 'calendar_monthly',
12-
'upcoming_releases' => (new Data)->getFutureReleases(),
12+
'upcoming_releases' => (new Data())->getFutureReleases(),
1313
'calendar' => require_once MODELS . 'calendar_monthly.php',
1414
]
1515
))->render();

0 commit comments

Comments
 (0)