Skip to content
Open
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
46 changes: 46 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# 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: 2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: PHPStan

on: pull_request

concurrency:
group: phpstan-${{ github.head_ref || github.run_id }}
cancel-in-progress: true

jobs:
phpstan-static-analysis:
runs-on: ubuntu-latest

name: static-phpstan-analysis
steps:
- name: Checkout
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- name: Get php version
id: versions
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1

- name: Set up php${{ steps.versions.outputs.php-available }}
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: ${{ steps.versions.outputs.php-available }}
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: Run static analysis
run: composer run phpstan
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"openapi": "generate-spec",
"phpstan": "vendor/bin/phpstan analyse -c phpstan.neon",
"psalm": "psalm --no-cache --threads=$(nproc)",
"psalm:dev": "@psalm",
"psalm:update-baseline": "psalm --threads=1 --update-baseline",
Expand Down
2 changes: 1 addition & 1 deletion lib/BackgroundJob/RetentionJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function run($argument): void {

$offset = '';
$limit = 1000;
while ($offset !== null) {
while (true) {
$fileIds = $this->tagMapper->getObjectIdsForTags((string)$tag, 'files', $limit, $offset);
$this->logger->debug('Checking retention for ' . count($fileIds) . ' files in this chunk');

Expand Down
18 changes: 4 additions & 14 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ public function getRetentions(): DataResponse {
* Create a retention rule
*
* @param int $tagid Tag the retention is based on
* @param 0|1|2|3 $timeunit Time unit of the retention (days, weeks, months, years)
* @param int<0, 3> $timeunit Time unit of the retention (days, weeks, months, years)
* @psalm-param Constants::UNIT_* $timeunit
* @param positive-int $timeamount Amount of time units that have to be passed
* @param 0|1 $timeafter Whether retention time is based creation time (0) or modification time (1)
* @param int<1, 32000> $timeamount Amount of time units that have to be passed
* @param int<0, 1> $timeafter Whether retention time is based creation time (0) or modification time (1)
Comment on lines -89 to +92

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so happy about converting enums to ranges :/ This makes the specifications worse and clients that generate code from it, too.

* @psalm-param Constants::MODE_* $timeafter
* @return DataResponse<Http::STATUS_BAD_REQUEST, array{error: 'tagid'|'timeunit'|'timeamount'|'timeafter'}, array{}>|DataResponse<Http::STATUS_CREATED, Files_RetentionRule, array{}>
*
Expand All @@ -103,16 +103,6 @@ public function addRetention(int $tagid, int $timeunit, int $timeamount, int $ti
return new DataResponse(['error' => 'tagid'], Http::STATUS_BAD_REQUEST);
}

if ($timeunit < 0 || $timeunit > 3) {
return new DataResponse(['error' => 'timeunit'], Http::STATUS_BAD_REQUEST);
}
if ($timeamount < 1 || $timeamount > 32_000) {
return new DataResponse(['error' => 'timeamount'], Http::STATUS_BAD_REQUEST);
}
if ($timeafter < 0 || $timeafter > 1) {
return new DataResponse(['error' => 'timeafter'], Http::STATUS_BAD_REQUEST);
}

// Fetch tag_id
$qb = $this->db->getQueryBuilder();
$qb->select('tag_id')
Expand Down Expand Up @@ -154,7 +144,7 @@ public function addRetention(int $tagid, int $timeunit, int $timeamount, int $ti
* Delete a retention rule
*
* @param int $id Retention rule to delete
* @return DataResponse<Http::STATUS_NO_CONTENT|Http::STATUS_NOT_FOUND, list<empty>, array{}>
* @return DataResponse<Http::STATUS_NO_CONTENT|Http::STATUS_NOT_FOUND, array{}, array{}>
Comment on lines -157 to +147

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should stay list<empty>

*
* 204: Retention rule deleted
* 404: Retention rule not found
Expand Down
25 changes: 11 additions & 14 deletions openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,28 +253,23 @@
"timeunit": {
"type": "integer",
"format": "int64",
"enum": [
0,
1,
2,
3
],
"description": "Time unit of the retention (days, weeks, months, years)"
"description": "Time unit of the retention (days, weeks, months, years)",
"minimum": 0,
"maximum": 3
},
"timeamount": {
"type": "integer",
"format": "int64",
"description": "Amount of time units that have to be passed",
"minimum": 1
"minimum": 1,
"maximum": 32000
},
"timeafter": {
"type": "integer",
"format": "int64",
"enum": [
0,
1
],
"description": "Whether retention time is based creation time (0) or modification time (1)"
"description": "Whether retention time is based creation time (0) or modification time (1)",
"minimum": 0,
"maximum": 1
}
}
}
Expand Down Expand Up @@ -489,7 +484,9 @@
"meta": {
"$ref": "#/components/schemas/OCSMeta"
},
"data": {}
"data": {
"type": "object"
}
}
}
}
Expand Down
12 changes: 12 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-or-later
parameters:
level: 5
paths:
- lib
scanFiles:
- tests/stub.phpstub
scanDirectories:
- vendor/nextcloud/ocp
ignoreErrors:
- '#on an unknown class Doctrine\\DBAL\\Schema\\Table#'
2 changes: 2 additions & 0 deletions tests/lib/Contoller/APIControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public function testAddRetentionInvalidTag(): void {
}

public function testAddRetentionInvalidTimeUnit(): void {
$this->markTestSkipped('Test is no longer applicable as the Dispatcher is limiting values');
$response = $this->api->addRetention(42, -1, 1);
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());

Expand All @@ -75,6 +76,7 @@ public function testAddRetentionInvalidTimeUnit(): void {
}

public function testAddRetentionInvalidTimeAmount(): void {
$this->markTestSkipped('Test is no longer applicable as the Dispatcher is limiting values');
$response = $this->api->addRetention(42, 3, 128_000);
$this->assertSame(Http::STATUS_BAD_REQUEST, $response->getStatus());
}
Comment on lines 69 to 82

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be removed now, right?

Expand Down
10 changes: 10 additions & 0 deletions vendor-bin/phpstan/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config": {
"platform": {
"php": "8.1"
}
},
"require-dev": {
"phpstan/phpstan": "^2.1.0"
}
}
80 changes: 80 additions & 0 deletions vendor-bin/phpstan/composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading