Skip to content

Commit 1e33791

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

File tree

60 files changed

+250
-203
lines changed

Some content is hidden

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

60 files changed

+250
-203
lines changed

judge/judgedaemon.main.php

Lines changed: 19 additions & 19 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,
@@ -945,7 +945,7 @@ private function fetchExecutableInternal(
945945
$filesArray = [];
946946
foreach ($files as $file) {
947947
$filename = $execbuilddir . '/' . $file['filename'];
948-
$content = base64_decode($file['content']);
948+
$content = base64_decode((string) $file['content']);
949949
file_put_contents($filename, $content);
950950
if ($file['is_executable']) {
951951
chmod($filename, 0755);
@@ -957,10 +957,10 @@ private function fetchExecutableInternal(
957957
];
958958
}
959959
unset($files);
960-
uasort($filesArray, fn(array $a, array $b) => strcmp($a['filename'], $b['filename']));
960+
uasort($filesArray, fn(array $a, array $b) => strcmp((string) $a['filename'], (string) $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
)
@@ -1251,8 +1251,8 @@ private function compile(
12511251
if ($compile_config['filter_compiler_files']) {
12521252
$picked = false;
12531253
foreach ($compile_config['language_extensions'] as $extension) {
1254-
$extensionLength = strlen($extension);
1255-
if (substr($file, -$extensionLength) === $extension) {
1254+
$extensionLength = strlen((string) $extension);
1255+
if (substr((string) $file, -$extensionLength) === $extension) {
12561256
$files[] = $file;
12571257
$picked = true;
12581258
break;
@@ -1264,7 +1264,7 @@ private function compile(
12641264
} else {
12651265
$files[] = $file;
12661266
}
1267-
if (file_put_contents($srcfile, base64_decode($source['content'])) === false) {
1267+
if (file_put_contents($srcfile, base64_decode((string) $source['content'])) === false) {
12681268
error("Could not create $srcfile");
12691269
}
12701270
}
@@ -1596,7 +1596,7 @@ private function runTestcase(
15961596
}
15971597

15981598
$new_judging_run = [
1599-
'runresult' => urlencode($result),
1599+
'runresult' => urlencode((string) $result),
16001600
'start_time' => urlencode((string)$startTime),
16011601
'end_time' => urlencode((string)microtime(true)),
16021602
'runtime' => urlencode((string)$runtime),
@@ -1757,7 +1757,7 @@ private function fetchTestcase(string $workdirpath, string $testcase_id, int $ju
17571757
unset($content);
17581758
foreach ($files as $file) {
17591759
$filename = $tcfile[$file['filename']];
1760-
file_put_contents($filename, base64_decode($file['content']));
1760+
file_put_contents($filename, base64_decode((string) $file['content']));
17611761
}
17621762
unset($files);
17631763

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

webapp/src/Command/CallApiActionCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public function __invoke(
8282
$files = [];
8383
if (in_array($method, [Request::METHOD_POST, Request::METHOD_PUT], true)) {
8484
foreach ($data as $dataItem) {
85-
$parts = explode('=', $dataItem, 2);
85+
$parts = explode('=', (string) $dataItem, 2);
8686
if (count($parts) !== 2) {
8787
$output->writeln(sprintf('Error: data item %s is not in key=value format', $dataItem));
8888
return Command::FAILURE;

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/Command/ScoreboardMergeCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,9 @@ public function __invoke(
372372
$pattern = str_replace(
373373
'ROOT_URL', preg_quote($rootUrl, '/'), $pattern
374374
);
375-
preg_match_all($pattern, $output, $matches);
375+
preg_match_all($pattern, (string) $output, $matches);
376376
$filesToAdd = array_merge($filesToAdd, $matches[1]);
377-
$output = preg_replace($pattern, $replace, $output);
377+
$output = preg_replace($pattern, $replace, (string) $output);
378378
}
379379

380380
$zip = new ZipArchive();

webapp/src/Controller/Jury/ClarificationController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public function viewAction(Request $request, int $id): Response
160160
if ($this->dj->getCurrentContest()) {
161161
$groupedCategories[$this->dj->getCurrentContest()->getShortname()][$key] = $value;
162162
} else {
163-
[$group] = explode(' - ', $value, 2);
163+
[$group] = explode(' - ', (string) $value, 2);
164164
$groupedCategories[$group][$key] = $value;
165165
}
166166
}
@@ -369,7 +369,7 @@ protected function processSubmittedClarification(
369369

370370

371371
$subject = $formData['subject'];
372-
[$cid, $probid] = explode('-', $subject);
372+
[$cid, $probid] = explode('-', (string) $subject);
373373

374374
$contest = $this->em->getReference(Contest::class, $cid);
375375
$clarification->setContest($contest);

webapp/src/Controller/Jury/ConfigController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public function indexAction(EventLogService $eventLogService, Request $request):
4848
if ($request->getMethod() == 'POST' && $request->request->has('save')) {
4949
$data = [];
5050
foreach ($request->request->all() as $key => $value) {
51-
if (str_starts_with($key, 'config_')) {
51+
if (str_starts_with((string) $key, 'config_')) {
5252
$valueToUse = $value;
5353
if (is_array($value)) {
5454
$firstItem = reset($value);
@@ -59,7 +59,7 @@ public function indexAction(EventLogService $eventLogService, Request $request):
5959
}
6060
}
6161
}
62-
$data[substr($key, strlen('config_'))] = $valueToUse;
62+
$data[substr((string) $key, strlen('config_'))] = $valueToUse;
6363
if ($key === 'config_lazy_eval_results' && $value !== DOMJudgeService::EVAL_DEMAND) {
6464
$this->dj->unblockJudgeTasks();
6565
}

webapp/src/Controller/Jury/ContestController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -956,9 +956,9 @@ private function checkTimezones(FormInterface $form): ?Response
956956
foreach (['Activate', 'Deactivate', 'Start', 'End', 'Freeze', 'Unfreeze'] as $timeString) {
957957
$tmpValue = $formData->{'get' . $timeString . 'timeString'}();
958958
if ($tmpValue !== '' && !is_null($tmpValue)) {
959-
if (preg_match("/\d{2}-\d{2}-\d{2}.*/", $tmpValue) === 1) {
959+
if (preg_match("/\d{2}-\d{2}-\d{2}.*/", (string) $tmpValue) === 1) {
960960
$chr = $tmpValue[10]; // The separator between date & time
961-
$fields = explode($chr, $tmpValue);
961+
$fields = explode($chr, (string) $tmpValue);
962962
// First field is the time, 2nd/3th might be timezone or offset
963963
$tmpValue = substr(str_replace($fields[0], '', $tmpValue), 1); // Also remove the separator
964964
if (str_contains($tmpValue, ' ')) {
@@ -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
}

0 commit comments

Comments
 (0)