Skip to content

Commit f42ad84

Browse files
committed
chore(code): apply Rector
Signed-off-by: Benjamin Gaussorgues <benjamin.gaussorgues@nextcloud.com>
1 parent d417e6e commit f42ad84

9 files changed

Lines changed: 25 additions & 25 deletions

File tree

.psalm-baseline.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,5 @@
5858
<RiskyTruthyFalsyComparison>
5959
<code><![CDATA[strrpos($version, '.')]]></code>
6060
</RiskyTruthyFalsyComparison>
61-
<UnusedMethod>
62-
<code><![CDATA[downloadProgressCallback]]></code>
63-
</UnusedMethod>
6461
</file>
6562
</files>

index.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function __construct(
8787
if (function_exists('opcache_invalidate')) {
8888
opcache_invalidate($versionFileName, true);
8989
}
90+
9091
if (!file_exists($versionFileName)) {
9192
// fallback to version in config.php
9293
$version = $this->getConfigOptionString('version');
@@ -376,7 +377,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
376377
/* Store first level children in an array to avoid trouble if changes happen while iterating */
377378
$children = [];
378379
while ($name = readdir($handle)) {
379-
if (in_array($name, ['.', '..'])) {
380+
if (in_array($name, ['.', '..'], true)) {
380381
continue;
381382
}
382383

@@ -775,7 +776,7 @@ private function downloadArchive(string $fromUrl, string $toLocation): bool {
775776

776777
curl_setopt_array($ch, [
777778
CURLOPT_NOPROGRESS => false,
778-
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
779+
CURLOPT_PROGRESSFUNCTION => $this->downloadProgressCallback(...),
779780
CURLOPT_FILE => $fp,
780781
]);
781782

@@ -886,6 +887,7 @@ public function verifyIntegrity(string $urlOverride = '', string $signature = ''
886887
'Custom download url provided. You need to provide a signature with --signature or skip integrity check with --no-verify.'
887888
);
888889
}
890+
889891
$signature = $this->getSignatureFromUpdater();
890892
}
891893

@@ -1349,11 +1351,8 @@ public function currentStep(): array {
13491351

13501352
if (isset($jsonData['step']) && $jsonData['step'] <= self::LAST_STEP && $jsonData['step'] > 0) {
13511353
$result['step'] = (int)$jsonData['step'];
1352-
if (isset($jsonData['state'])) {
1353-
$result['state'] = (string)$jsonData['state'];
1354-
} else {
1355-
$result['state'] = 'start';
1356-
}
1354+
$result['state'] = isset($jsonData['state']) ? (string)$jsonData['state'] : 'start';
1355+
13571356
if ($result['step'] === self::LAST_STEP && $result['state'] !== 'start') {
13581357
return [];
13591358
}

lib/UpdateCommand.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class UpdateCommand extends Command {
3131
protected bool $skipIntegrityCheck = false;
3232

3333
protected string $urlOverride = '';
34+
3435
protected string $signature = '';
3536

3637
/** Strings of text for stages of updater */
@@ -137,11 +138,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
137138
}
138139

139140
// Check if already a step is in process
140-
if ($this->ignoreState) {
141-
$currentStep = [];
142-
} else {
143-
$currentStep = $this->updater->currentStep();
144-
}
141+
$currentStep = $this->ignoreState ? [] : $this->updater->currentStep();
142+
145143
$stepNumber = 0;
146144
if ($currentStep !== []) {
147145
$stepState = $currentStep['state'] ?? '';
@@ -158,6 +156,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
158156
);
159157
return -1;
160158
}
159+
161160
$output->writeln('Found an ongoing update, continue from step ' . $stepNumber);
162161
}
163162

@@ -466,6 +465,7 @@ protected function executeStep(int $step, OutputInterface $output): array {
466465
$this->updater->silentLog('[info] Skipping integrity check as requested');
467466
break;
468467
}
468+
469469
$this->updater->verifyIntegrity($this->urlOverride, $this->signature);
470470
break;
471471
case 6:

lib/Updater.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ public function __construct(
7171
if (function_exists('opcache_invalidate')) {
7272
opcache_invalidate($versionFileName, true);
7373
}
74+
7475
if (!file_exists($versionFileName)) {
7576
// fallback to version in config.php
7677
$version = $this->getConfigOptionString('version');
@@ -360,7 +361,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
360361
/* Store first level children in an array to avoid trouble if changes happen while iterating */
361362
$children = [];
362363
while ($name = readdir($handle)) {
363-
if (in_array($name, ['.', '..'])) {
364+
if (in_array($name, ['.', '..'], true)) {
364365
continue;
365366
}
366367

@@ -759,7 +760,7 @@ private function downloadArchive(string $fromUrl, string $toLocation): bool {
759760

760761
curl_setopt_array($ch, [
761762
CURLOPT_NOPROGRESS => false,
762-
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
763+
CURLOPT_PROGRESSFUNCTION => $this->downloadProgressCallback(...),
763764
CURLOPT_FILE => $fp,
764765
]);
765766

@@ -870,6 +871,7 @@ public function verifyIntegrity(string $urlOverride = '', string $signature = ''
870871
'Custom download url provided. You need to provide a signature with --signature or skip integrity check with --no-verify.'
871872
);
872873
}
874+
873875
$signature = $this->getSignatureFromUpdater();
874876
}
875877

@@ -1333,11 +1335,8 @@ public function currentStep(): array {
13331335

13341336
if (isset($jsonData['step']) && $jsonData['step'] <= self::LAST_STEP && $jsonData['step'] > 0) {
13351337
$result['step'] = (int)$jsonData['step'];
1336-
if (isset($jsonData['state'])) {
1337-
$result['state'] = (string)$jsonData['state'];
1338-
} else {
1339-
$result['state'] = 'start';
1340-
}
1338+
$result['state'] = isset($jsonData['state']) ? (string)$jsonData['state'] : 'start';
1339+
13411340
if ($result['step'] === self::LAST_STEP && $result['state'] !== 'start') {
13421341
return [];
13431342
}

tests/checkSameCodeBase.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ function findDiffPos($original, $copy) {
5858
foreach ($iterator as $path => $fileInfo) {
5959
$fileName = explode($libDir, $path)[1];
6060

61-
if (in_array($fileName, $excludedFiles)) {
61+
if (in_array($fileName, $excludedFiles, true)) {
6262
continue;
6363
}
6464

@@ -67,7 +67,7 @@ function findDiffPos($original, $copy) {
6767
$fileContent = explode("namespace NC\\Updater;\n", $fileContent, 2)[1];
6868
$fileContent = preg_replace('/^use [^\\\\]*;\n/m', '', $fileContent);
6969

70-
$fileContent = trim($fileContent);
70+
$fileContent = trim((string)$fileContent);
7171

7272
if (in_array(str_contains($indexPhpContent, $fileContent), [0, false], true)) {
7373
$failedFiles[] = $fileName;

tests/features/bootstrap/FeatureContext.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,12 @@ public function theArchiveForVersionIsAvailableLocally(string $version): void {
231231
if (curl_exec($ch) === false) {
232232
throw new \Exception('Curl error: ' . curl_error($ch));
233233
}
234+
234235
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
235236
if ($httpCode !== 200) {
236237
throw new \Exception('Download failed for ' . $url . ' - HTTP code: ' . $httpCode);
237238
}
239+
238240
curl_close($ch);
239241
fclose($fp);
240242
}
@@ -282,6 +284,7 @@ private function runUpdaterWithLocalFileUrl(string $version, bool $noVerify): vo
282284
if ($noVerify) {
283285
$args .= ' --no-verify';
284286
}
287+
285288
exec('./updater ' . $args . ' 2>&1', $output, $returnCode);
286289

287290
// sleep to let the opcache do it's work and invalidate the status.php
@@ -505,7 +508,7 @@ public function theConfigKeyIsSetTo(string $key, mixed $value, string $type = 's
505508
return;
506509
}
507510

508-
if (!in_array($type, ['string', 'boolean', 'integer', 'double'])) {
511+
if (!in_array($type, ['string', 'boolean', 'integer', 'double'], true)) {
509512
throw new Exception('Invalid type given: ' . $type);
510513
}
511514

updater.phar

-70 Bytes
Binary file not shown.

vendor/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
'NC\\Updater\\UpdateCommand' => $baseDir . '/lib/UpdateCommand.php',
2626
'NC\\Updater\\UpdateException' => $baseDir . '/lib/UpdateException.php',
2727
'NC\\Updater\\Updater' => $baseDir . '/lib/Updater.php',
28+
'NC\\Updater\\Version' => $baseDir . '/lib/Version.php',
2829
'Normalizer' => $vendorDir . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
2930
'Psr\\Container\\ContainerExceptionInterface' => $vendorDir . '/psr/container/src/ContainerExceptionInterface.php',
3031
'Psr\\Container\\ContainerInterface' => $vendorDir . '/psr/container/src/ContainerInterface.php',

vendor/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ class ComposerStaticInitcbbead1010db4afef500f7adc2b6cac3
103103
'NC\\Updater\\UpdateCommand' => __DIR__ . '/../..' . '/lib/UpdateCommand.php',
104104
'NC\\Updater\\UpdateException' => __DIR__ . '/../..' . '/lib/UpdateException.php',
105105
'NC\\Updater\\Updater' => __DIR__ . '/../..' . '/lib/Updater.php',
106+
'NC\\Updater\\Version' => __DIR__ . '/../..' . '/lib/Version.php',
106107
'Normalizer' => __DIR__ . '/..' . '/symfony/polyfill-intl-normalizer/Resources/stubs/Normalizer.php',
107108
'Psr\\Container\\ContainerExceptionInterface' => __DIR__ . '/..' . '/psr/container/src/ContainerExceptionInterface.php',
108109
'Psr\\Container\\ContainerInterface' => __DIR__ . '/..' . '/psr/container/src/ContainerInterface.php',

0 commit comments

Comments
 (0)