Skip to content

Commit c54e150

Browse files
Apply "risky" PHP migration formatter rules (#2668)
This PR continues our ongoing effort to modernize the codebase by applying stricter code formatting rules. This PR also helps us better take advantage of new PHP features. Most of the rules applied here are "risky" in cases which do not apply to CDash.
1 parent 43b055a commit c54e150

File tree

78 files changed

+257
-266
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+257
-266
lines changed

.php-cs-fixer.dist.php

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
<?php
22

3-
$finder = PhpCsFixer\Finder::create()
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$finder = Finder::create()
47
->exclude('app/cdash/config')
58
->exclude('bootstrap/cache')
69
->exclude('node_modules')
@@ -9,23 +12,25 @@
912
->exclude('_build')
1013
->exclude('resources')
1114
->exclude('public')
15+
->exclude('app/cdash/tests/kwtest/simpletest')
1216
->notPath('app/cdash/tests/config.test.local.php')
13-
->in(__DIR__)
14-
;
17+
->in(__DIR__);
1518

16-
$config = new PhpCsFixer\Config();
19+
$config = new Config();
1720
return $config->setRules([
18-
'@PSR12' => true,
19-
'@PHP82Migration' => true,
20-
'@Symfony' => true,
21-
'yoda_style' => false,
22-
'blank_line_before_statement' => false,
23-
'phpdoc_summary' => false,
24-
'concat_space' => ['spacing' => 'one'],
25-
'increment_style' => ['style' => 'post'],
26-
'fully_qualified_strict_types' => ['import_symbols' => true],
27-
'global_namespace_import' => ['import_classes' => true, 'import_constants' => null, 'import_functions' => null],
28-
'phpdoc_align' => ['align' => 'left'],
29-
])
30-
->setFinder($finder)
31-
;
21+
'@PSR12' => true,
22+
'@PSR12:risky' => true,
23+
'@PHP82Migration' => true,
24+
'@PHP82Migration:risky' => true,
25+
'@Symfony' => true,
26+
'yoda_style' => false,
27+
'blank_line_before_statement' => false,
28+
'phpdoc_summary' => false,
29+
'concat_space' => ['spacing' => 'one'],
30+
'increment_style' => ['style' => 'post'],
31+
'fully_qualified_strict_types' => ['import_symbols' => true],
32+
'global_namespace_import' => ['import_classes' => true, 'import_constants' => null, 'import_functions' => null],
33+
'phpdoc_align' => ['align' => 'left'],
34+
'declare_strict_types' => false, // TODO: turn this back on. Currently causes errors...
35+
'void_return' => false, // TODO: turn this back on. Currently causes errors...
36+
])->setFinder($finder);

app/Http/Controllers/BuildController.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,7 @@ public function viewUpdatePageContent(): JsonResponse
666666

667667
$directoryarray = array_unique($directoryarray);
668668

669-
usort($directoryarray, function ($a, $b) {
670-
return $a > $b ? 1 : 0;
671-
});
669+
usort($directoryarray, fn ($a, $b) => $a > $b ? 1 : 0);
672670
usort($updatearray1, function ($a, $b) {
673671
// Extract directory
674672
$filenamea = $a['filename'];
@@ -1009,9 +1007,7 @@ public function apiViewBuildError(): JsonResponse
10091007
}
10101008

10111009
if ($this->build->IsParentBuild()) {
1012-
$response['numSubprojects'] = count(array_unique(array_map(function ($buildError) {
1013-
return $buildError['subprojectid'];
1014-
}, $response['errors'])));
1010+
$response['numSubprojects'] = count(array_unique(array_map(fn ($buildError) => $buildError['subprojectid'], $response['errors'])));
10151011
}
10161012

10171013
$pageTimer->end($response);

app/Http/Controllers/BuildPropertiesController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,7 @@ public function apiBuildProperties(): JsonResponse
116116
}
117117
$response['defecttypes'] = $defect_types;
118118

119-
$defect_types = array_filter($defect_types, function ($defect_type) {
120-
return $defect_type['selected'];
121-
});
119+
$defect_types = array_filter($defect_types, fn ($defect_type) => $defect_type['selected']);
122120

123121
// Construct an SQL SELECT clause for the requested types of defects.
124122
$defect_keys = [];

app/Http/Controllers/CoverageController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1794,9 +1794,7 @@ public function apiCompareCoverage(): JsonResponse
17941794

17951795
if (!empty($subproject_groups)) {
17961796
// At this point it is safe to remove any empty $coveragegroups from our response.
1797-
$coveragegroups_response = array_filter($coveragegroups, function ($group) {
1798-
return $group['label'] === 'Total' || !empty($group['coverages']);
1799-
});
1797+
$coveragegroups_response = array_filter($coveragegroups, fn ($group) => $group['label'] === 'Total' || !empty($group['coverages']));
18001798

18011799
// Report coveragegroups as a list, not an associative array.
18021800
$coveragegroups_response = array_values($coveragegroups_response);

app/Http/Controllers/RemoteProcessingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function requeueSubmissionFile(): Response
111111

112112
// Requeue the file with exponential backoff.
113113
PendingSubmissions::IncrementForBuildId($buildid);
114-
$delay = (int) pow(config('cdash.retry_base'), $retry_handler->Retries);
114+
$delay = ((int) config('cdash.retry_base')) ** $retry_handler->Retries;
115115
ProcessSubmission::dispatch($filename, $projectid, $buildid, md5_file(Storage::path("inbox/{$filename}")))->delay(now()->addSeconds($delay));
116116
return response('OK', Response::HTTP_OK);
117117
}

app/Jobs/ProcessSubmission.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private function requeueSubmissionFile($buildid): bool
116116

117117
// Requeue the file with exponential backoff.
118118
PendingSubmissions::IncrementForBuildId($this->buildid);
119-
$delay = pow(config('cdash.retry_base'), $retry_handler->Retries);
119+
$delay = ((int) config('cdash.retry_base')) ** $retry_handler->Retries;
120120
if (config('queue.default') === 'sqs-fifo') {
121121
// Special handling for sqs-fifo, which does not support per-message delays.
122122
sleep(10);

app/Utils/RepositoryUtils.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,7 @@ public static function linkify_compiler_output($projecturl, $source_dir, $revisi
709709
}
710710

711711
// Make sure we specify a protocol so this isn't interpreted as a relative path.
712-
if (strpos($projecturl, '//') === false) {
712+
if (!str_contains($projecturl, '//')) {
713713
$projecturl = '//' . $projecturl;
714714
}
715715
$repo_link = "<a class='cdash-link' href='$projecturl/blob/$revision";
@@ -776,7 +776,7 @@ public static function post_github_pull_request_comment(Project $project, $pull_
776776
$repo = null;
777777
$repositories = $project->GetRepositories();
778778
foreach ($repositories as $repository) {
779-
if (strpos($repository['url'], 'github.com') !== false) {
779+
if (str_contains($repository['url'], 'github.com')) {
780780
$repo = $repository;
781781
break;
782782
}

app/cdash/app/Controller/Api/Index.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,7 @@ public function getDailyBuilds(): array
189189
$sql .= $this->limitSQL;
190190

191191
$builds = DB::select($sql, $query_params);
192-
return array_map(function ($item) {
193-
return (array) $item;
194-
}, $builds);
192+
return array_map(fn ($item) => (array) $item, $builds);
195193
}
196194

197195
public function getDynamicBuilds(): array

app/cdash/app/Controller/Api/QueryTests.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function rowSurvivesTestOutputFilter($row, &$build)
8686
$match_length = 0;
8787

8888
foreach ($this->testOutputExclude as $exclude) {
89-
if (strpos($test_output, $exclude) !== false) {
89+
if (str_contains($test_output, $exclude)) {
9090
return false;
9191
}
9292
}

app/cdash/app/Controller/Api/TestOverview.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public function getResponse()
163163

164164
if ($status === 'passed') {
165165
$all_tests[$test_name]['passed']++;
166-
} elseif (strpos($row['details'], 'Timeout') !== false) {
166+
} elseif (str_contains($row['details'], 'Timeout')) {
167167
$all_tests[$test_name]['timeout']++;
168168
} else {
169169
$all_tests[$test_name]['failed']++;

0 commit comments

Comments
 (0)