diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php index 03e052c7d3..0e5fb1832e 100644 --- a/.php-cs-fixer.dist.php +++ b/.php-cs-fixer.dist.php @@ -13,15 +13,14 @@ ->exclude('resources') ->exclude('public') ->exclude('app/cdash/tests/kwtest/simpletest') - ->notPath('app/cdash/tests/config.test.local.php') ->in(__DIR__); $config = new Config(); return $config->setRules([ '@PSR12' => true, '@PSR12:risky' => true, - '@PHP82Migration' => true, - '@PHP82Migration:risky' => true, + '@PHP8x2Migration' => true, + '@PHP8x2Migration:risky' => true, '@Symfony' => true, 'yoda_style' => false, 'blank_line_before_statement' => false, @@ -32,4 +31,25 @@ 'global_namespace_import' => ['import_classes' => true, 'import_constants' => null, 'import_functions' => null], 'phpdoc_align' => ['align' => 'left'], 'declare_strict_types' => false, // TODO: turn this back on. Currently causes errors... + // The following rules are a subset of @Symfony:risky and should eventually be replaced by the full ruleset. + 'array_push' => true, + 'combine_nested_dirname' => true, + 'dir_constant' => true, + 'ereg_to_preg' => true, + 'fopen_flag_order' => true, + 'function_to_constant' => true, + 'get_class_to_class_keyword' => true, + 'implode_call' => true, + 'is_null' => true, + 'logical_operators' => true, + 'long_to_shorthand_operator' => true, + 'modernize_strpos' => ['modernize_stripos' => true], + 'modernize_types_casting' => true, + 'no_homoglyph_names' => true, + 'no_useless_sprintf' => true, + 'non_printable_character' => true, + 'ordered_traits' => true, + 'self_accessor' => true, + 'set_type_to_cast' => true, + 'string_line_ending' => true, ])->setFinder($finder); diff --git a/app/Console/Commands/RemoveUser.php b/app/Console/Commands/RemoveUser.php index b8ef8d3f79..168dadb7f4 100644 --- a/app/Console/Commands/RemoveUser.php +++ b/app/Console/Commands/RemoveUser.php @@ -37,7 +37,7 @@ public function __construct() public function handle(): void { $email = $this->option('email'); - if (is_null($email)) { + if (null === $email) { $this->error('You must specify the --email option'); return; } diff --git a/app/Console/Commands/SaveUser.php b/app/Console/Commands/SaveUser.php index 0520f3c736..dd03bf4030 100644 --- a/app/Console/Commands/SaveUser.php +++ b/app/Console/Commands/SaveUser.php @@ -37,7 +37,7 @@ public function __construct() public function handle(): void { $email = $this->option('email'); - if (is_null($email)) { + if (null === $email) { $this->error('You must specify the --email option'); return; } @@ -57,7 +57,7 @@ public function handle(): void $options = ['firstname', 'lastname', 'institution', 'password']; foreach ($options as $option_name) { $option_value = $this->option($option_name); - if (!is_null($option_value)) { + if (null !== $option_value) { if ($option_name === 'password') { $option_value = password_hash($option_value, PASSWORD_DEFAULT); } diff --git a/app/Http/Controllers/AdminController.php b/app/Http/Controllers/AdminController.php index d8e7246a22..c644c76023 100644 --- a/app/Http/Controllers/AdminController.php +++ b/app/Http/Controllers/AdminController.php @@ -14,12 +14,12 @@ public function removeBuilds(): View|RedirectResponse { @set_time_limit(0); - $projectid = intval($_GET['projectid'] ?? 0); + $projectid = (int) ($_GET['projectid'] ?? 0); $alert = ''; // get date info here - @$dayTo = intval($_POST['dayFrom']); + @$dayTo = (int) $_POST['dayFrom']; if (empty($dayTo)) { $time = strtotime('2000-01-01 00:00:00'); @@ -43,12 +43,12 @@ public function removeBuilds(): View|RedirectResponse $yearTo = date('Y'); $monthTo = date('m'); } else { - $dayFrom = intval($_POST['dayFrom']); - $monthFrom = intval($_POST['monthFrom']); - $yearFrom = intval($_POST['yearFrom']); - $dayTo = intval($_POST['dayTo']); - $monthTo = intval($_POST['monthTo']); - $yearTo = intval($_POST['yearTo']); + $dayFrom = (int) $_POST['dayFrom']; + $monthFrom = (int) $_POST['monthFrom']; + $yearFrom = (int) $_POST['yearFrom']; + $dayTo = (int) $_POST['dayTo']; + $monthTo = (int) $_POST['monthTo']; + $yearTo = (int) $_POST['yearTo']; } // List the available projects diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index 524c27c18a..0c8edd3620 100755 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -89,7 +89,7 @@ protected function validator(array $data) */ public function create(array $data): ?User { - if (is_null($data['institution'])) { + if (null === $data['institution']) { $data['institution'] = ''; } return User::create([ diff --git a/app/Http/Controllers/AuthTokenController.php b/app/Http/Controllers/AuthTokenController.php index f359074773..6b3e99108d 100644 --- a/app/Http/Controllers/AuthTokenController.php +++ b/app/Http/Controllers/AuthTokenController.php @@ -47,7 +47,7 @@ public function createToken(Request $request): JsonResponse } if ($request->input('scope') !== AuthToken::SCOPE_FULL_ACCESS) { - $projectid = intval($request->input('projectid')); + $projectid = (int) $request->input('projectid'); if (!is_numeric($projectid)) { return response()->json(['error' => 'Invalid projectid'], Response::HTTP_BAD_REQUEST); } diff --git a/app/Http/Controllers/BuildController.php b/app/Http/Controllers/BuildController.php index cbaaf3366c..b6985431e7 100644 --- a/app/Http/Controllers/BuildController.php +++ b/app/Http/Controllers/BuildController.php @@ -114,7 +114,7 @@ public function apiBuildSummary(): JsonResponse { $pageTimer = new PageTimer(); - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); $date = TestingDay::get($this->project, $this->build->StartTime); @@ -504,7 +504,7 @@ public function buildOverview(): View|RedirectResponse $currentstarttime = get_dates($date, $this->project->NightlyTime)[1]; // Return the available groups - $selected_group = intval($_POST['groupSelection'] ?? 0); + $selected_group = (int) ($_POST['groupSelection'] ?? 0); // Check the builds $beginning_timestamp = $currentstarttime; @@ -580,7 +580,7 @@ public function viewUpdatePageContent(): JsonResponse { $pageTimer = new PageTimer(); - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); $date = TestingDay::get($this->project, $this->build->StartTime); $response = begin_JSON_response(); @@ -821,13 +821,13 @@ public function build_file(int $build_id, int $file_id): StreamedResponse public function ajaxBuildNote(): View { - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); Gate::authorize('edit-project', $this->project); $notes = DB::select('SELECT * FROM comments WHERE buildid=? ORDER BY timestamp ASC', [$this->build->Id]); foreach ($notes as $note) { /** @var User $user */ - $user = User::where('id', intval($note->userid))->first(); + $user = User::where('id', (int) $note->userid)->first(); $note->user = $user; } @@ -851,7 +851,7 @@ public function apiViewBuildError(): JsonResponse $response = begin_JSON_response(); $response['title'] = $this->project->Name; - $type = intval($_GET['type'] ?? 0); + $type = (int) ($_GET['type'] ?? 0); $date = TestingDay::get($this->project, $this->build->StartTime); get_dashboard_JSON($this->project->Name, $date, $response); @@ -928,7 +928,7 @@ public function apiViewBuildError(): JsonResponse label.id=label2buildfailure.labelid AND label2buildfailure.buildfailureid=? ORDER BY text ASC - ', [intval($resolvedBuildFailure['id'])], $marshaledResolvedBuildFailure); + ', [(int) $resolvedBuildFailure['id']], $marshaledResolvedBuildFailure); } $marshaledResolvedBuildFailure = array_merge($marshaledResolvedBuildFailure, [ @@ -1077,7 +1077,7 @@ public function apiViewConfigure(): JsonResponse public function apiBuildUpdateGraph(): JsonResponse { - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); // Find previous submissions from this build. $query_result = DB::select(' @@ -1118,7 +1118,7 @@ public function apiBuildUpdateGraph(): JsonResponse public function apiGetPreviousBuilds(): JsonResponse { - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); // Take subproject into account, such that if there is one, then the // previous builds must be associated with the same subproject. @@ -1190,7 +1190,7 @@ public function apiGetPreviousBuilds(): JsonResponse */ public function apiBuildExpected(): JsonResponse { - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); $rule = new BuildGroupRule($this->build); return response()->json([ 'expected' => $rule->GetExpected(), @@ -1372,7 +1372,7 @@ private function restApiGet(): JsonResponse $gmtdate = strtotime($last_good_submit . ' UTC'); } else { // Find the oldest submission for this build. - if (is_null($first_submit)) { + if (null === $first_submit) { pdo_execute($oldest_build_stmt, $query_params); $first_submit = $oldest_build_stmt->fetchColumn(); } diff --git a/app/Http/Controllers/BuildNoteController.php b/app/Http/Controllers/BuildNoteController.php index 9017744d2a..7a55b72834 100644 --- a/app/Http/Controllers/BuildNoteController.php +++ b/app/Http/Controllers/BuildNoteController.php @@ -16,7 +16,7 @@ final class BuildNoteController extends AbstractBuildController { public function apiViewNotes(): JsonResponse { - $this->setBuildById(intval($_GET['buildid'] ?? 0)); + $this->setBuildById((int) ($_GET['buildid'] ?? 0)); $pageTimer = new PageTimer(); diff --git a/app/Http/Controllers/BuildPropertiesController.php b/app/Http/Controllers/BuildPropertiesController.php index 47db6d24e9..a0a869e833 100644 --- a/app/Http/Controllers/BuildPropertiesController.php +++ b/app/Http/Controllers/BuildPropertiesController.php @@ -54,7 +54,7 @@ public function apiBuildProperties(): JsonResponse // Default to the current date. $date = date(FMT_DATE); } - if (is_null($beginning_timestamp)) { + if (null === $beginning_timestamp) { [$unused, $beginning_timestamp] = get_dates($date, $this->project->NightlyTime); $datetime = new DateTime(); $datetime->setTimestamp($beginning_timestamp); @@ -256,7 +256,7 @@ private function get_defects_for_builds() $stmt = $pdo->prepare($sql); $stmt->execute($_GET['buildid']); - if (!$this->gather_defects($stmt, $prettyname, $defects_response) && !is_null($sql2)) { + if (!$this->gather_defects($stmt, $prettyname, $defects_response) && null !== $sql2) { $stmt = $pdo->prepare($sql2); $stmt->execute($_GET['buildid']); $this->gather_defects($stmt, $prettyname, $defects_response); diff --git a/app/Http/Controllers/CDash.php b/app/Http/Controllers/CDash.php index 1790693c58..14e8296318 100755 --- a/app/Http/Controllers/CDash.php +++ b/app/Http/Controllers/CDash.php @@ -102,7 +102,7 @@ protected function getRequestContents() // Possible values of $redirect are null, 0, 1 and a ResponseRedirect. // Clearly we want to ignore when null or int, otherwise $redirect should // be returned - return is_numeric($redirect) || is_null($redirect) ? $content : $redirect; + return is_numeric($redirect) || null === $redirect ? $content : $redirect; } /** diff --git a/app/Http/Controllers/CoverageController.php b/app/Http/Controllers/CoverageController.php index 293e9cfd4b..40ece91fe6 100644 --- a/app/Http/Controllers/CoverageController.php +++ b/app/Http/Controllers/CoverageController.php @@ -31,7 +31,7 @@ public function viewCoverage(): View|RedirectResponse { @set_time_limit(0); - $this->setBuildById(intval($_GET['buildid'] ?? -1)); + $this->setBuildById((int) ($_GET['buildid'] ?? -1)); @$date = $_GET['date']; if ($date != null) { @@ -56,7 +56,7 @@ public function viewCoverage(): View|RedirectResponse SELECT role FROM user2project WHERE userid=? AND projectid=? - ', [intval($userid), intval($this->project->Id)]); + ', [(int) $userid, (int) $this->project->Id]); if (!empty($user2project)) { $role = $user2project['role']; } @@ -75,9 +75,9 @@ public function viewCoverage(): View|RedirectResponse SELECT coveragethreshold FROM subprojectgroup WHERE projectid=? AND id=? - ', [intval($this->project->Id), intval($this->build->GroupId)]); + ', [(int) $this->project->Id, (int) $this->build->GroupId]); if (!empty($row) && isset($row['coveragethreshold'])) { - $threshold = intval($row['coveragethreshold']); + $threshold = (int) $row['coveragethreshold']; } } @@ -97,7 +97,7 @@ public function viewCoverage(): View|RedirectResponse FROM coverage WHERE buildid=? GROUP BY buildid - ', [intval($this->build->Id)]); + ', [(int) $this->build->Id]); $xml .= add_XML_value('starttime', date('l, F d Y', strtotime($this->build->StartTime))); $xml .= add_XML_value('loctested', $coverage_array['loctested']); @@ -133,7 +133,7 @@ public function viewCoverage(): View|RedirectResponse label.id=label2coverage.labelid AND label2coverage.coverageid=coverage.id AND coverage.buildid=? - ', [intval($this->build->Id)]); + ', [(int) $this->build->Id]); foreach ($covlabels as $row) { $labels[$row['id']] = $row['text']; } @@ -154,10 +154,10 @@ public function viewCoverage(): View|RedirectResponse label2coverage.labelid=? AND coverage.buildid=? AND coverage.id=label2coverage.coverageid - ', [intval($id), intval($this->build->Id)]); + ', [(int) $id, (int) $this->build->Id]); - $loctested = intval($row['loctested']); - $locuntested = intval($row['locuntested']); + $loctested = (int) $row['loctested']; + $locuntested = (int) $row['locuntested']; $percentcoverage = compute_percentcoverage($loctested, $locuntested); $xml .= '