Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/rector-apply.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Apply rector changes

on:
workflow_dispatch:
schedule:
# At 14:30 on Sundays
- cron: "30 14 * * 0"

permissions:
contents: read

jobs:
build:
runs-on: ubuntu-latest

name: rector-apply

steps:
- name: Checkout
id: checkout
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
with:
persist-credentials: false
ref: ${{ github.event.repository.default_branch }}

- name: Get php version
id: versions
uses: icewind1991/nextcloud-version-matrix@8a7bac6300b2f0f3100088b297995a229558ddba # v1.3.2

- name: Set up php${{ steps.versions.outputs.php-min }}
uses: shivammathur/setup-php@accd6127cb78bee3e8082180cb391013d204ef9f # 2.37.0
with:
php-version: ${{ steps.versions.outputs.php-min }}
extensions: bz2, ctype, curl, dom, fileinfo, gd, iconv, intl, json, libxml, mbstring, openssl, pcntl, posix, session, simplexml, xmlreader, xmlwriter, zip, zlib, sqlite, pdo_sqlite
coverage: none
ini-file: development
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies
run: |
composer remove nextcloud/ocp --dev --no-scripts
composer i

- name: Rector
run: composer run rector

- name: Create Pull Request
uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1
with:
token: ${{ secrets.COMMAND_BOT_PAT }}
commit-message: "refactor: Apply rector changes"
committer: GitHub <noreply@github.com>
author: nextcloud-command <nextcloud-command@users.noreply.github.com>
signoff: true
branch: automated/noid/rector-changes
title: "Apply rector changes"
labels: |
technical debt
3. to review
3 changes: 0 additions & 3 deletions .psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,5 @@
<RiskyTruthyFalsyComparison>
<code><![CDATA[strrpos($version, '.')]]></code>
</RiskyTruthyFalsyComparison>
<UnusedMethod>
<code><![CDATA[downloadProgressCallback]]></code>
</UnusedMethod>
</file>
</files>
13 changes: 6 additions & 7 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public function __construct(
if (function_exists('opcache_invalidate')) {
opcache_invalidate($versionFileName, true);
}

if (!file_exists($versionFileName)) {
// fallback to version in config.php
$version = $this->getConfigOptionString('version');
Expand Down Expand Up @@ -376,7 +377,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
/* Store first level children in an array to avoid trouble if changes happen while iterating */
$children = [];
while ($name = readdir($handle)) {
if (in_array($name, ['.', '..'])) {
if (in_array($name, ['.', '..'], true)) {
continue;
}

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

curl_setopt_array($ch, [
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
CURLOPT_PROGRESSFUNCTION => $this->downloadProgressCallback(...),
CURLOPT_FILE => $fp,
]);

Expand Down Expand Up @@ -886,6 +887,7 @@ public function verifyIntegrity(string $urlOverride = '', string $signature = ''
'Custom download url provided. You need to provide a signature with --signature or skip integrity check with --no-verify.'
);
}

$signature = $this->getSignatureFromUpdater();
}

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

if (isset($jsonData['step']) && $jsonData['step'] <= self::LAST_STEP && $jsonData['step'] > 0) {
$result['step'] = (int)$jsonData['step'];
if (isset($jsonData['state'])) {
$result['state'] = (string)$jsonData['state'];
} else {
$result['state'] = 'start';
}
$result['state'] = isset($jsonData['state']) ? (string)$jsonData['state'] : 'start';

if ($result['step'] === self::LAST_STEP && $result['state'] !== 'start') {
return [];
}
Expand Down
10 changes: 5 additions & 5 deletions lib/UpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class UpdateCommand extends Command {
protected bool $skipIntegrityCheck = false;

protected string $urlOverride = '';

protected string $signature = '';

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

// Check if already a step is in process
if ($this->ignoreState) {
$currentStep = [];
} else {
$currentStep = $this->updater->currentStep();
}
$currentStep = $this->ignoreState ? [] : $this->updater->currentStep();

$stepNumber = 0;
if ($currentStep !== []) {
$stepState = $currentStep['state'] ?? '';
Expand All @@ -158,6 +156,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
return -1;
}

$output->writeln('Found an ongoing update, continue from step ' . $stepNumber);
}

Expand Down Expand Up @@ -466,6 +465,7 @@ protected function executeStep(int $step, OutputInterface $output): array {
$this->updater->silentLog('[info] Skipping integrity check as requested');
break;
}

$this->updater->verifyIntegrity($this->urlOverride, $this->signature);
break;
case 6:
Expand Down
13 changes: 6 additions & 7 deletions lib/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public function __construct(
if (function_exists('opcache_invalidate')) {
opcache_invalidate($versionFileName, true);
}

if (!file_exists($versionFileName)) {
// fallback to version in config.php
$version = $this->getConfigOptionString('version');
Expand Down Expand Up @@ -360,7 +361,7 @@ private function getRecursiveDirectoryIterator(string $folder, array $excludedPa
/* Store first level children in an array to avoid trouble if changes happen while iterating */
$children = [];
while ($name = readdir($handle)) {
if (in_array($name, ['.', '..'])) {
if (in_array($name, ['.', '..'], true)) {
continue;
}

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

curl_setopt_array($ch, [
CURLOPT_NOPROGRESS => false,
CURLOPT_PROGRESSFUNCTION => [$this, 'downloadProgressCallback'],
CURLOPT_PROGRESSFUNCTION => $this->downloadProgressCallback(...),
CURLOPT_FILE => $fp,
]);

Expand Down Expand Up @@ -870,6 +871,7 @@ public function verifyIntegrity(string $urlOverride = '', string $signature = ''
'Custom download url provided. You need to provide a signature with --signature or skip integrity check with --no-verify.'
);
}

$signature = $this->getSignatureFromUpdater();
}

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

if (isset($jsonData['step']) && $jsonData['step'] <= self::LAST_STEP && $jsonData['step'] > 0) {
$result['step'] = (int)$jsonData['step'];
if (isset($jsonData['state'])) {
$result['state'] = (string)$jsonData['state'];
} else {
$result['state'] = 'start';
}
$result['state'] = isset($jsonData['state']) ? (string)$jsonData['state'] : 'start';

if ($result['step'] === self::LAST_STEP && $result['state'] !== 'start') {
return [];
}
Expand Down
11 changes: 8 additions & 3 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,26 @@
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

use Nextcloud\Rector\Set\NextcloudSets;
use Rector\Config\RectorConfig;

return RectorConfig::configure()
->withPaths([
__DIR__ . '/lib',
__DIR__ . '/tests',
])
->withImportNames(importShortClasses:false)
->withSkipPath(__DIR__ . '/tests/data')
->withImportNames(importShortClasses: false)
->withPreparedSets(
codeQuality: true,
codingStyle: true,
deadCode: true,
earlyReturn: true,
instanceOf: true,
privatization: true,
strictBooleans: true,
)
->withPhpSets(php82: true);
->withPhpSets(php82: true)
->withSets([
NextcloudSets::NEXTCLOUD_34,
]);
;
4 changes: 2 additions & 2 deletions tests/checkSameCodeBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function findDiffPos($original, $copy) {
foreach ($iterator as $path => $fileInfo) {
$fileName = explode($libDir, $path)[1];

if (in_array($fileName, $excludedFiles)) {
if (in_array($fileName, $excludedFiles, true)) {
continue;
}

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

$fileContent = trim($fileContent);
$fileContent = trim((string)$fileContent);

if (in_array(str_contains($indexPhpContent, $fileContent), [0, false], true)) {
$failedFiles[] = $fileName;
Expand Down
5 changes: 4 additions & 1 deletion tests/features/bootstrap/FeatureContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,10 +231,12 @@ public function theArchiveForVersionIsAvailableLocally(string $version): void {
if (curl_exec($ch) === false) {
throw new \Exception('Curl error: ' . curl_error($ch));
}

$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($httpCode !== 200) {
throw new \Exception('Download failed for ' . $url . ' - HTTP code: ' . $httpCode);
}

curl_close($ch);
fclose($fp);
}
Expand Down Expand Up @@ -282,6 +284,7 @@ private function runUpdaterWithLocalFileUrl(string $version, bool $noVerify): vo
if ($noVerify) {
$args .= ' --no-verify';
}

exec('./updater ' . $args . ' 2>&1', $output, $returnCode);

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

if (!in_array($type, ['string', 'boolean', 'integer', 'double'])) {
if (!in_array($type, ['string', 'boolean', 'integer', 'double'], true)) {
throw new Exception('Invalid type given: ' . $type);
}

Expand Down
Binary file modified updater.phar
Binary file not shown.
6 changes: 3 additions & 3 deletions vendor-bin/rector/composer.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"require-dev": {
"rector/rector": "^1.2"
}
"require-dev": {
"nextcloud/rector": "^0.5.1"
}
}
Loading
Loading