Skip to content

Commit

Permalink
PhpStan 2.0 + remove parenthesis for class instantiation in PHP8.4
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Nov 27, 2024
1 parent 7e395cb commit a82af4a
Show file tree
Hide file tree
Showing 47 changed files with 150 additions and 132 deletions.
2 changes: 1 addition & 1 deletion app/classes/ReleaseInsights/Beta.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function __construct(public int $release = BETA) {
$this->count = (int) explode('b', FIREFOX_BETA)[1];

// We get the number of betas from the planned schedule
$schedule = (new Release((string) $release))->getSchedule();
$schedule = new Release((string) $release)->getSchedule();
$schedule = array_keys($schedule);
$schedule = array_filter($schedule, fn($label) => str_starts_with($label, 'beta_'));
$this->number_betas = count($schedule);
Expand Down
8 changes: 4 additions & 4 deletions app/classes/ReleaseInsights/CalendarMonthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ class CalendarMonthly
*/
public static function getMonthsToLastPlannedRelease(): array
{
$start = (new DateTime('now'))->modify('first day of this month');
$start = new DateTime('now')->modify('first day of this month');

/* For unit tests which work on stale data, we fake a past date */
if (defined('TESTING_CONTEXT')) {
$start = new DateTime('2023-11-01');
}

/* The end date is the last planned major release */
$end = array_key_last((new Data())->getFutureReleases());
$end = (new Data())->getFutureReleases()[$end];
$end = (new DateTime($end))->modify('first day of next month');
$end = array_key_last(new Data()->getFutureReleases());
$end = new Data()->getFutureReleases()[$end];
$end = new DateTime($end)->modify('first day of next month');
$period = new DatePeriod(
$start,
DateInterval::createFromDateString('1 month'),
Expand Down
2 changes: 1 addition & 1 deletion app/classes/ReleaseInsights/Duration.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function weeks(): float
public function isWorkDay(DateTime $day): bool
{
// We don't consider the current day as a working day
if ($day->format('Y-m-d') === (new DateTime())->format('Y-m-d')) {
if ($day->format('Y-m-d') === new DateTime()->format('Y-m-d')) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion app/classes/ReleaseInsights/Performance.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Performance
* Utility function to return the memory used by a script
* and the time needed to compute the data.
*
* @return array<int> [Memory peak in bytes, Memory peak in MB, Computation time]
* @return array<int, float|int<1, max>> [Memory peak in bytes, Memory peak in MB, Computation time]
*/
public static function getData(): array
{
Expand Down
4 changes: 2 additions & 2 deletions app/classes/ReleaseInsights/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public function getSchedule(): array
*/
public function getFutureSchedule(): array
{
$all_releases = (new Data($this->product_details))->getMajorReleases();
$all_releases = new Data($this->product_details)->getMajorReleases();
if (! array_key_exists($this->version->normalized, $all_releases)) {
return ['error' => 'Not enough data for this version number.'];
}
Expand Down Expand Up @@ -155,7 +155,7 @@ public function getPastSchedule() : array
);

// Transform all the DateTime objects in the $schedule array into formated date strings
$format_date = fn(string $day): string => (new DateTime($day))->format('Y-m-d H:i:sP');
$format_date = fn(string $day): string => new DateTime($day)->format('Y-m-d H:i:sP');

$schedule = [
'nightly_start' => $format_date(Nightly::cycleStart($this->version->int)),
Expand Down
4 changes: 2 additions & 2 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ public static function isBuildID(string $buildid): bool
}

// The date shouldn't be in the future
$date = (new DateTime($buildid))->format('Ymd');
$today = (new DateTime())->format('Ymd');
$date = new DateTime($buildid)->format('Ymd');
$today = new DateTime()->format('Ymd');

if ($date > $today) {
return false;
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/404.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

use ReleaseInsights\{Model, Template};

$data = (new Model('404'))->get();
$data = new Model('404')->get();

http_response_code(404);

(new Template(
new Template(
'regular.html.twig',
[
'page_title' => '404: Page Not Found',
'css_page_id' => 'notfound',
'page_content' => $data,
]
))->render();
)->render();
6 changes: 3 additions & 3 deletions app/controllers/about.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

use ReleaseInsights\{Model, Template};

$data = (new Model('about'))->get();
$data = new Model('about')->get();

(new Template(
new Template(
'regular.html.twig',
[
'page_title' => 'Firefox Trains - List of public APIs and pages',
'css_page_id' => 'about',
'page_content' => $data,
]
))->render();
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/beta_crashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_beta_crashes'))->get()))->render();
new Json(
new Model('api_beta_crashes')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/esr_releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_esr_releases'))->get()))->render();
new Json(
new Model('api_esr_releases')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/external.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_external'))->get()))->render();
new Json(
new Model('api_external')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/firefox_releases.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_firefox_releases'))->get()))->render();
new Json(
new Model('api_firefox_releases')->get()
)->render();
4 changes: 2 additions & 2 deletions app/controllers/api/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

// We want to send simplified Json data for our public API
$data = [];
foreach ((new Model('api_nightly'))->get() as $key => $values) {
foreach (new Model('api_nightly')->get() as $key => $values) {
$data[$key] = $values['revision'];
}

(new Json($data))->render();
new Json($data)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/nightly_crashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_nightly_crashes'))->get()))->render();
new Json(
new Model('api_nightly_crashes')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/release_duty.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_release_duty'))->get()))->render();
new Json(
new Model('api_release_duty')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/release_owners.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,7 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_release_owners'))->get()))->render();
new Json(
new Model('api_release_owners')->get()
)->render();

4 changes: 3 additions & 1 deletion app/controllers/api/release_schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_release_schedule'))->get()))->render();
new Json(
new Model('api_release_schedule')->get()
)->render();
4 changes: 3 additions & 1 deletion app/controllers/api/wellness_days.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

use ReleaseInsights\{Json, Model};

(new Json((new Model('api_wellness_days'))->get()))->render();
new Json(
new Model('api_wellness_days')->get()
)->render();
6 changes: 3 additions & 3 deletions app/controllers/beta.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use ReleaseInsights\{Model, Template};

[$beta, $bug_details, $uplift_counter, $stats, $known_top_crashes, $crash_bugs] = (new Model('beta'))->get();
[$beta, $bug_details, $uplift_counter, $stats, $known_top_crashes, $crash_bugs] = new Model('beta')->get();

(new Template(
new Template(
'beta.html.twig',
[
'page_title' => 'Betas this cycle',
Expand All @@ -18,4 +18,4 @@
'known_top_crashes' => $known_top_crashes,
'crash_bugs' => $crash_bugs,
]
))->render();
)->render();
6 changes: 3 additions & 3 deletions app/controllers/calendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

use ReleaseInsights\{Model, Template};

$data = (new Model('calendar'))->get();
$data = new Model('calendar')->get();

(new Template(
new Template(
'calendar.html.twig',
[
'page_title' => 'Firefox Release Calendar',
Expand All @@ -15,4 +15,4 @@
'upcoming_releases' => $data['future'],
'upcoming_quarters' => array_count_values(array_column($data['future'], 'quarter')),
]
))->render();
)->render();
6 changes: 3 additions & 3 deletions app/controllers/calendar_monthly.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

use ReleaseInsights\{CalendarMonthly, Model, Template};

$data = (new Model('calendar_monthly'))->get();
$data = new Model('calendar_monthly')->get();

(new Template(
new Template(
'calendar_monthly.html.twig',
[
'page_title' => 'General calendar of upcoming Firefox release milestones',
'css_page_id' => 'calendar_monthly',
'upcoming_months' => CalendarMonthly::getMonthsToLastPlannedRelease(),
'calendar' => $data,
]
))->render();
)->render();


6 changes: 3 additions & 3 deletions app/controllers/homepage.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
$beta_is_the_next_ESR,
$nightly_auto_updates,
$nightly_emergency_message,
] = (new Model('home'))->get();
] = new Model('home')->get();

(new Template(
new Template(
'overview.html.twig',
[
'page_title' => 'What Firefox trains are we in?',
Expand All @@ -33,4 +33,4 @@
'nightly_auto_updates' => $nightly_auto_updates,
'nightly_emergency' => $nightly_emergency_message,
]
))->render();
)->render();
2 changes: 1 addition & 1 deletion app/controllers/ics_release_schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
exit("We don't provide schedule calendars for past releases.");
}

[$filename, $ics_calendar] = (new Model('ics'))->get();
[$filename, $ics_calendar] = new Model('ics')->get();

header('Content-Type: text/calendar; charset=utf-8');
// header('Content-Type: text/plain; charset=utf-8');
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
$known_top_crashes,
$fallback_nightly,
$warning,
] = (new Model('nightly'))->get();
] = new Model('nightly')->get();

(new Template(
new Template(
'nightly.html.twig',
[
'page_title' => 'Nightly builds (crashes and bug fixes)',
Expand All @@ -43,4 +43,4 @@
'fallback_nightly' => $fallback_nightly,
'warning_message' => $warning,
]
))->render();
)->render();
18 changes: 9 additions & 9 deletions app/controllers/release.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
}

// Planned releases
$upcoming_releases = (new Data())->getFutureReleases();
$owners = (new Data())->getOwners();
$upcoming_releases = new Data()->getFutureReleases();
$owners = new Data()->getOwners();

$css_page_id = match (true) {
$requested_version_int === NIGHTLY => 'release_nightly',
Expand All @@ -34,10 +34,10 @@

// Releases before version 4 were handled completely differently
if ($requested_version_int < 4) {
[$dot_release_count, $release_date] = (new Model('pre_firefox4_release'))->get();
[$dot_release_count, $release_date] = new Model('pre_firefox4_release')->get();
$template_data += ['dot_release_count' => $dot_release_count];
$template_data += ['release_date' => $release_date];
(new Template('pre4_release.html.twig', $template_data))->render();
new Template('pre4_release.html.twig', $template_data)->render();
return;
}

Expand All @@ -55,7 +55,7 @@
$current_ESR,
$release_date,
$esr_calendar,
] = (new Model('esr_release'))->get();
] = new Model('esr_release')->get();

$template_data = array_merge($template_data, [
'page_title' => 'Firefox ESR schedule',
Expand All @@ -67,7 +67,7 @@
'esr_majors' => ESR::$esr_releases,
]);

(new Template('esr_release.html.twig', $template_data))->render();
new Template('esr_release.html.twig', $template_data)->render();

return;
}
Expand Down Expand Up @@ -98,7 +98,7 @@
$no_planned_dot_releases,
$release_rollout,
$uptake,
] = (new Model('past_release'))->get();
] = new Model('past_release')->get();

$template_file = 'past_release.html.twig';
$template_data = array_merge($template_data, [
Expand Down Expand Up @@ -140,7 +140,7 @@
$rollout,
$wellness_days,
$latest_nightly,
] = (new Model('future_release'))->get();
] = new Model('future_release')->get();
$template_file = 'future_release.html.twig';
$template_data = array_merge($template_data, [
'release_date' => $release_date,
Expand All @@ -163,4 +163,4 @@
]);
}

(new Template($template_file, $template_data))->render();
new Template($template_file, $template_data)->render();
6 changes: 3 additions & 3 deletions app/controllers/release_owners.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use ReleaseInsights\{Model, Template};

(new Template(
new Template(
'release_owners.html.twig',
[
'page_title' => 'Major releases per release owner',
'css_page_id' => 'release_owners',
'owners' => (new Model('owners'))->get(),
'owners' => new Model('owners')->get(),
]
))->render();
)->render();
Loading

0 comments on commit a82af4a

Please sign in to comment.