diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml new file mode 100644 index 0000000000..af4e6fe012 --- /dev/null +++ b/.github/workflows/rector.yml @@ -0,0 +1,88 @@ +# SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors +# SPDX-License-Identifier: MIT + +name: Rector + +on: + pull_request: + +permissions: + contents: read + +concurrency: + group: rector-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +jobs: + changes: + runs-on: ubuntu-latest-low + permissions: + contents: read + pull-requests: read + + outputs: + src: ${{ steps.changes.outputs.src}} + + steps: + - uses: dorny/paths-filter@ceb8a2b8f2d89434be7ff52d3de7ec3738c5cc9d # v4.0.3 + id: changes + continue-on-error: true + with: + filters: | + src: + - '.github/workflows/**' + - 'appinfo/**' + - 'lib/**' + - 'tests/**' + - 'vendor-bin/**' + - 'composer.json' + - 'composer.lock' + - 'rector.php' + - '**.php' + + strict: + runs-on: ubuntu-latest + + needs: changes + if: ${{ needs.changes.outputs.src != 'false' && github.event_name != 'push' && github.repository_owner != 'nextcloud-gmbh' }} + + steps: + - name: Checkout + uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 + with: + persist-credentials: false + submodules: true + + - name: Set up php + uses: shivammathur/setup-php@f3e473d116dcccaddc5834248c87452386958240 # 2.37.2 + with: + php-version: 8.2 + 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 i + + - name: Rector + run: composer run rector:check + + - name: Show changes + if: always() + run: git diff --exit-code + + summary: + permissions: + contents: none + runs-on: ubuntu-latest-low + needs: [changes, strict] + + if: always() + + name: rector-summary + + steps: + - name: Summary status + run: if ${{ needs.changes.outputs.src != 'false' && needs.strict.result != 'success' }}; then exit 1; fi diff --git a/lib/Activity/ActivityManager.php b/lib/Activity/ActivityManager.php index 452b98591d..ec9dc6b4bd 100644 --- a/lib/Activity/ActivityManager.php +++ b/lib/Activity/ActivityManager.php @@ -91,9 +91,7 @@ public function __construct( * @psalm-param string|null $author */ public function triggerEvent(string $objectType, Row2|Table|View|Column $object, string $subject, array|string|null $additionalParams = [], array|string|null $author = null) { - if ($author === null) { - $author = $this->userId; - } + $author ??= $this->userId; try { $event = $this->createEvent($objectType, $object, $subject, $additionalParams, $author); diff --git a/lib/Db/ContextMapper.php b/lib/Db/ContextMapper.php index 3b677afc64..0da199335e 100644 --- a/lib/Db/ContextMapper.php +++ b/lib/Db/ContextMapper.php @@ -103,9 +103,7 @@ protected function formatResultRows(array $rows, ?string $userId) { 'display_mode_default' => (int)$item['display_mode_default'], ]; if ($userId !== null) { - if ($item['display_mode'] === null) { - $item['display_mode'] = $item['display_mode_default']; - } + $item['display_mode'] ??= $item['display_mode_default']; $carry[$item['share_id']]['display_mode'] = (int)$item['display_mode']; } return $carry; @@ -130,9 +128,7 @@ protected function formatResultRows(array $rows, ?string $userId) { // empty Context return $carry; } - if (!isset($carry[$item['page_id']])) { - $carry[$item['page_id']] = ['content' => []]; - } + $carry[$item['page_id']] ??= ['content' => []]; $carry[$item['page_id']]['id'] = (int)$item['page_id']; $carry[$item['page_id']]['page_type'] = $item['page_type']; if ($item['node_rel_id'] !== null) { diff --git a/lib/Db/Row2Mapper.php b/lib/Db/Row2Mapper.php index b0cfa89d9a..4e6478cb17 100644 --- a/lib/Db/Row2Mapper.php +++ b/lib/Db/Row2Mapper.php @@ -692,9 +692,7 @@ private function parseEntities(IResult $result, array $sleeves): array { $column = $this->columnMapper->find($rowData['column_id']); $columnType = $column->getType(); - if (!isset($cellMapperCache[$columnType])) { - $cellMapperCache[$columnType] = $this->getCellMapperFromType($columnType); - } + $cellMapperCache[$columnType] ??= $this->getCellMapperFromType($columnType); $value = $cellMapperCache[$columnType]->formatRowData($column, $rowData); $compositeKey = (string)$rowData['row_id'] . ',' . (string)$rowData['column_id']; if ($cellMapperCache[$columnType]->hasMultipleValues()) { diff --git a/lib/Migration/Version2020Date20260513185340.php b/lib/Migration/Version2020Date20260513185340.php index 067989d001..6e91736462 100644 --- a/lib/Migration/Version2020Date20260513185340.php +++ b/lib/Migration/Version2020Date20260513185340.php @@ -74,9 +74,7 @@ private function applyColumnOptionsUpdateIfNecessary(IQueryBuilder $query, int $ } foreach ($selectionOptions as &$selectionOption) { - if (!isset($selectionOption['uuid'])) { - $selectionOption['uuid'] = Uuid::v7()->toRfc4122(); - } + $selectionOption['uuid'] ??= Uuid::v7()->toRfc4122(); } $updatedSelectionOptions = json_encode($selectionOptions); diff --git a/lib/Migration/Version2202Date20260825184226.php b/lib/Migration/Version2202Date20260825184226.php index f42aec3443..7cc99b0343 100644 --- a/lib/Migration/Version2202Date20260825184226.php +++ b/lib/Migration/Version2202Date20260825184226.php @@ -88,9 +88,7 @@ private function applyColumnOptionsUpdateIfNecessary(IQueryBuilder $query, int $ } foreach ($selectionOptions as &$selectionOption) { - if (!isset($selectionOption['uuid'])) { - $selectionOption['uuid'] = Uuid::v7()->toRfc4122(); - } + $selectionOption['uuid'] ??= Uuid::v7()->toRfc4122(); } unset($selectionOption); diff --git a/lib/Service/ColumnService.php b/lib/Service/ColumnService.php index 52a84b03c1..47c88240e1 100644 --- a/lib/Service/ColumnService.php +++ b/lib/Service/ColumnService.php @@ -614,9 +614,7 @@ public function delete(int $id, bool $skipRowCleanup = false, ?string $userId = public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $viewId, array $titles, array $dataTypes, ?string $userId, bool $createUnknownColumns, int &$countCreatedColumns, int &$countMatchingColumns): array { $result = []; - if ($userId === null) { - $userId = $this->userId; - } + $userId ??= $this->userId; if ($viewId) { $allColumns = $this->findAllByView($viewId, $userId); } elseif ($tableId) { @@ -638,10 +636,7 @@ public function findOrCreateColumnsByTitleForTableAsArray(?int $tableId, ?int $v } $result[$i] = ''; } - // if there are no columns at all - if (!isset($result[$i])) { - $result[$i] = ''; - } + $result[$i] ??= ''; // if column was not found if ($result[$i] === '' && $createUnknownColumns && $dataTypes[$i]['type'] !== Column::TYPE_META_ID) { $description = $this->l->t('This column was automatically created by the import service.'); diff --git a/lib/Service/PermissionsService.php b/lib/Service/PermissionsService.php index d75479c0d0..dc68798e23 100644 --- a/lib/Service/PermissionsService.php +++ b/lib/Service/PermissionsService.php @@ -64,9 +64,7 @@ public function __construct( * @throws InternalError */ public function preCheckUserId(?string $userId = null, bool $canBeEmpty = true): string { - if ($userId === null) { - $userId = $this->userId; - } + $userId ??= $this->userId; if ($userId === null) { $e = new \Exception(); diff --git a/lib/Service/RelationService.php b/lib/Service/RelationService.php index 5928e13727..6d0ca9fade 100644 --- a/lib/Service/RelationService.php +++ b/lib/Service/RelationService.php @@ -104,9 +104,7 @@ private function groupColumnsByTarget(array $columns): array { } $target = sprintf('%s_%s_%s', $settings['relationType'], $settings['targetId'], $settings['labelColumn']); - if (!isset($groups[$target])) { - $groups[$target] = []; - } + $groups[$target] ??= []; $groups[$target][] = $column; } diff --git a/lib/Service/RowService.php b/lib/Service/RowService.php index 95baa53324..d55456b102 100644 --- a/lib/Service/RowService.php +++ b/lib/Service/RowService.php @@ -661,9 +661,7 @@ public function updateSet( throw new InternalError(static::class . ' - ' . __FUNCTION__ . ': ' . $e->getMessage()); } } else { - if ($tableId === null) { - $tableId = $item->getTableId(); - } + $tableId ??= $item->getTableId(); if ($tableId !== $item->getTableId()) { $e = new \Exception('Row does not belong to table with id ' . $tableId); $this->logger->error($e->getMessage(), ['exception' => $e]); diff --git a/lib/Service/TableService.php b/lib/Service/TableService.php index acc7d24fca..5d5b704cbd 100644 --- a/lib/Service/TableService.php +++ b/lib/Service/TableService.php @@ -120,9 +120,7 @@ public function findAll(?string $userId = null, bool $skipTableEnhancement = fal // clean duplicates foreach ($sharedTables as $sharedTable) { - if (!isset($allTables[$sharedTable->getId()])) { - $allTables[$sharedTable->getId()] = $sharedTable; - } + $allTables[$sharedTable->getId()] ??= $sharedTable; } } diff --git a/tests/integration/features/bootstrap/FeatureContext.php b/tests/integration/features/bootstrap/FeatureContext.php index 7278b1e12d..2677ae91cc 100644 --- a/tests/integration/features/bootstrap/FeatureContext.php +++ b/tests/integration/features/bootstrap/FeatureContext.php @@ -2143,9 +2143,7 @@ public function sendRequestFullUrl($verb, $fullUrl, $body = null, array $headers } protected function getUserCookieJar($user) { - if (!isset($this->cookieJars[$user])) { - $this->cookieJars[$user] = new CookieJar(); - } + $this->cookieJars[$user] ??= new CookieJar(); return $this->cookieJars[$user]; }