Skip to content

Commit 0450d7b

Browse files
Run rector to upgrade syntax to php 8.2+
1 parent 3fe9239 commit 0450d7b

Some content is hidden

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

45 files changed

+196
-147
lines changed

judge/judgedaemon.main.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ private function initialize(): void
240240
$domserver_languages = dj_json_decode($this->request('languages', 'GET'));
241241
foreach ($domserver_languages as $language) {
242242
$id = $language['id'];
243-
if (key_exists($id, $this->langexts)) {
243+
if (array_key_exists($id, $this->langexts)) {
244244
$this->langexts[$id] = $language['extensions'];
245245
}
246246
}
@@ -551,7 +551,7 @@ private function handleTask(string $type, array $row, ?string &$lastWorkdir, str
551551
$this->endpoints[$this->endpointID]['retrying'] = false;
552552

553553
logmsg(LOG_INFO,
554-
"⇝ Received " . sizeof($row) . " '" . $type . "' judge tasks (endpoint $this->endpointID)");
554+
"⇝ Received " . count($row) . " '" . $type . "' judge tasks (endpoint $this->endpointID)");
555555

556556
if ($type == 'prefetch') {
557557
$this->handlePrefetchTask($row, $lastWorkdir, $workdirpath);
@@ -763,14 +763,14 @@ private function request(string $url, string $verb = 'GET', $data = '', bool $fa
763763
}
764764
}
765765
if ($trial == BACKOFF_STEPS) {
766-
$errstr = $errstr . " Retry limit reached.";
766+
$errstr .= " Retry limit reached.";
767767
} else {
768768
$retry_in_sec = $delay_in_sec + BACKOFF_JITTER_SEC * random_int(0, mt_getrandmax()) / mt_getrandmax();
769769
$warnstr = $errstr . " This request will be retried after about " .
770770
round($retry_in_sec, 2) . "sec... (" . $trial . "/" . BACKOFF_STEPS . ")";
771771
warning($warnstr);
772772
dj_sleep($retry_in_sec);
773-
$delay_in_sec = $delay_in_sec * BACKOFF_FACTOR;
773+
$delay_in_sec *= BACKOFF_FACTOR;
774774
}
775775
}
776776
if (!$succeeded) {
@@ -865,7 +865,7 @@ private function runCommandSafe(array $command_parts, &$retval = DONT_CARE, $log
865865
return false;
866866
}
867867

868-
$command = implode(' ', array_map('dj_escapeshellarg', $command_parts));
868+
$command = implode(' ', array_map(dj_escapeshellarg(...), $command_parts));
869869

870870
logmsg(LOG_DEBUG, "Executing command: $command");
871871
system($command, $retval_local);
@@ -917,7 +917,7 @@ private function fetchExecutableInternal(
917917
string $hash,
918918
bool $combined_run_compare = false
919919
): array {
920-
$execdir = join('/', [
920+
$execdir = implode('/', [
921921
$workdirpath,
922922
'executable',
923923
$type,
@@ -959,8 +959,8 @@ private function fetchExecutableInternal(
959959
unset($files);
960960
uasort($filesArray, fn(array $a, array $b) => strcmp($a['filename'], $b['filename']));
961961
$computedHash = md5(
962-
join(
963-
array_map(
962+
implode(
963+
'', array_map(
964964
fn($file) => $file['hash'] . $file['filename'] . $file['is_executable'],
965965
$filesArray
966966
)
@@ -1767,10 +1767,10 @@ private function fetchTestcase(string $workdirpath, string $testcase_id, int $ju
17671767

17681768
private function initsignals(): void
17691769
{
1770-
pcntl_signal(SIGTERM, [self::class, 'signalHandler']);
1771-
pcntl_signal(SIGINT, [self::class, 'signalHandler']);
1772-
pcntl_signal(SIGHUP, [self::class, 'signalHandler']);
1773-
pcntl_signal(SIGUSR1, [self::class, 'signalHandler']);
1770+
pcntl_signal(SIGTERM, self::signalHandler(...));
1771+
pcntl_signal(SIGINT, self::signalHandler(...));
1772+
pcntl_signal(SIGHUP, self::signalHandler(...));
1773+
pcntl_signal(SIGUSR1, self::signalHandler(...));
17741774
}
17751775
}
17761776

webapp/composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@
109109
"phpstan/phpstan": "^2.0",
110110
"phpstan/phpstan-doctrine": "^2.0",
111111
"phpunit/phpunit": "^9.6",
112+
"rector/rector": "^2.2",
112113
"sebastian/diff": "*",
113114
"squizlabs/php_codesniffer": "*",
114115
"symfony/debug-bundle": "7.4.*",

webapp/composer.lock

Lines changed: 62 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

webapp/rector.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
7+
8+
return RectorConfig::configure()
9+
->withPaths([
10+
__DIR__ . '/config',
11+
__DIR__ . '/public',
12+
__DIR__ . '/resources',
13+
__DIR__ . '/src',
14+
__DIR__ . '/tests',
15+
])
16+
// uncomment to reach your current PHP version
17+
->withPhpSets()
18+
->withComposerBased(twig: true, doctrine: true, phpunit: true, symfony: true)
19+
->withTypeCoverageLevel(0)
20+
->withDeadCodeLevel(0)
21+
->withCodeQualityLevel(0)
22+
->withSkip([NullToStrictStringFuncCallArgRector::class]);

webapp/src/Command/ResetUserPasswordCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public function __invoke(
3737
$style->error('Can not find user with username ' . $username);
3838
return Command::FAILURE;
3939
}
40-
$password = $password ?? Utils::generatePassword();
40+
$password ??= Utils::generatePassword();
4141
$user->setPassword(
4242
$this->passwordHasher->hashPassword($user, $password)
4343
);

webapp/src/Controller/Jury/ContestController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,7 @@ private function checkTimezones(FormInterface $form): ?Response
967967
$fields = explode('+', $tmpValue);
968968
} elseif (str_contains($tmpValue, '-')) {
969969
$fields = explode('-', $tmpValue);
970-
} elseif (substr($tmpValue, -1) === 'Z') {
970+
} elseif (str_ends_with($tmpValue, 'Z')) {
971971
$timeZones[] = 'UTC';
972972
continue;
973973
}

webapp/src/Controller/Jury/ExecutableController.php

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function indexAction(Request $request): Response
7474
foreach (['compare', 'run', 'full_debug'] as $config_script) {
7575
try {
7676
$configScripts[] = (string)$this->config->get('default_' . $config_script);
77-
} catch (PHPInvalidArgumentException $e) {
77+
} catch (PHPInvalidArgumentException) {
7878
// If not found this is an older database, as we only use this for visual changes ignore this error;
7979
}
8080
}
@@ -129,22 +129,13 @@ public function indexAction(Request $request): Response
129129
}
130130
$execdata['execid']['cssclass'] = 'execid';
131131
$type = $execdata['type']['value'];
132-
switch ($type) {
133-
case 'compare':
134-
$execdata['icon']['icon'] = 'code-compare';
135-
break;
136-
case 'compile':
137-
$execdata['icon']['icon'] = 'language';
138-
break;
139-
case 'debug':
140-
$execdata['icon']['icon'] = 'bug';
141-
break;
142-
case 'run':
143-
$execdata['icon']['icon'] = 'person-running';
144-
break;
145-
default:
146-
$execdata['icon']['icon'] = 'question';
147-
}
132+
$execdata['icon']['icon'] = match ($type) {
133+
'compare' => 'code-compare',
134+
'compile' => 'language',
135+
'debug' => 'bug',
136+
'run' => 'person-running',
137+
default => 'question',
138+
};
148139
$execdata['badges']['value'] = $badges;
149140

150141
if ($this->isGranted('ROLE_ADMIN')) {

webapp/src/Controller/Jury/JudgehostController.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -206,9 +206,7 @@ public function indexAction(Request $request): Response
206206
];
207207
}
208208

209-
usort($judgehosts_table, function (array $a, array $b) {
210-
return strnatcasecmp($a['data']['hostname']['value'], $b['data']['hostname']['value']);
211-
});
209+
usort($judgehosts_table, fn(array $a, array $b) => strnatcasecmp($a['data']['hostname']['value'], $b['data']['hostname']['value']));
212210

213211
$data = [
214212
'judgehosts' => $judgehosts_table,

webapp/src/Controller/Jury/ProblemController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@ public function testcasesAction(Request $request, int $probId): Response
788788
if (!empty($lockedContests)) {
789789
$this->addFlash('warning',
790790
'Problem belongs to locked contest ('
791-
. implode($lockedContests)
791+
. implode('', $lockedContests)
792792
. ', disallowing editing.');
793793
}
794794
$data = [

webapp/src/Controller/Jury/RejudgingController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ public function viewAction(
383383

384384
// Only load the statistics if desired. The query is quite long and can result in much data, so only have it run
385385
// when needed or when we don't have a lot of data to load.
386-
$showStatistics = $showStatistics ?? $onlyAHandfulOfSubmissions;
386+
$showStatistics ??= $onlyAHandfulOfSubmissions;
387387
if ($showStatistics && count($repetitions) > 0) {
388388
$stats = $this->getStats($rejudging);
389389
} else {

0 commit comments

Comments
 (0)