Skip to content
Draft
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
16 changes: 3 additions & 13 deletions lib/Controller/APIController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*
* 200: List retention rules
*/
public function getRetentions(): DataResponse {

Check failure on line 44 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Type list<array<string, bool|int<0, max>>> in generic type OCP\AppFramework\Http\DataResponse<int, list<array<string, bool|int<0, max>>>, array> in PHPDoc tag @return is not subtype of template type T of OCP\AppFramework\Http\DataResponseType of class OCP\AppFramework\Http\DataResponse.
$qb = $this->db->getQueryBuilder();

$qb->select('*')
Expand Down Expand Up @@ -79,40 +79,30 @@
}));
}

return new DataResponse($result);

Check failure on line 82 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Parameter #1 $data of class OCP\AppFramework\Http\DataResponse constructor expects T of OCP\AppFramework\Http\DataResponseType, list<array<string, int|true>> given.

Check failure on line 82 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Method OCA\Files_Retention\Controller\APIController::getRetentions() should return OCP\AppFramework\Http\DataResponse<200, list<array{id: int<1, max>, tagid: int<1, max>, timeunit: 0|1|2|3, timeamount: int<1, max>, timeafter: 0|1, hasJob: bool}>, array{}> but returns OCP\AppFramework\Http\DataResponse<200, OCP\AppFramework\Http\DataResponseType, array{}>.
}

/**
* 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<0, 1> $timeafter Whether retention time is based creation time (0) or modification time (1)
* @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{}>
*
* 201: Retention rule created
* 400: At least one of the parameters was invalid
*/
public function addRetention(int $tagid, int $timeunit, int $timeamount, int $timeafter = Constants::MODE_CTIME): DataResponse {

Check failure on line 99 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Type array<string, string> in generic type OCP\AppFramework\Http\DataResponse<int, array<string, string>, array> in PHPDoc tag @return is not subtype of template type T of OCP\AppFramework\Http\DataResponseType of class OCP\AppFramework\Http\DataResponse.

Check failure on line 99 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Type array<string, bool|int<0, max>> in generic type OCP\AppFramework\Http\DataResponse<int, array<string, bool|int<0, max>>, array> in PHPDoc tag @return is not subtype of template type T of OCP\AppFramework\Http\DataResponseType of class OCP\AppFramework\Http\DataResponse.
try {
$this->tagManager->getTagsByIds((string)$tagid);
} catch (\InvalidArgumentException) {
return new DataResponse(['error' => 'tagid'], Http::STATUS_BAD_REQUEST);

Check failure on line 103 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Parameter #1 $data of class OCP\AppFramework\Http\DataResponse constructor expects T of OCP\AppFramework\Http\DataResponseType, array<string, string> given.

Check failure on line 103 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Method OCA\Files_Retention\Controller\APIController::addRetention() should return OCP\AppFramework\Http\DataResponse<201, array{id: int<1, max>, tagid: int<1, max>, timeunit: 0|1|2|3, timeamount: int<1, max>, timeafter: 0|1, hasJob: bool}, array{}>|OCP\AppFramework\Http\DataResponse<400, array{error: 'tagid'|'timeafter'|'timeamount'|'timeunit'}, array{}> but returns OCP\AppFramework\Http\DataResponse<400, OCP\AppFramework\Http\DataResponseType, array{}>.
}

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

$qb = $this->db->getQueryBuilder();
$qb->insert('retention')
->setValue('tag_id', $qb->createNamedParameter($tagid))
Expand All @@ -126,7 +116,7 @@
//Insert cronjob
$this->jobList->add(RetentionJob::class, ['tag' => $tagid]);

return new DataResponse([

Check failure on line 119 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Parameter #1 $data of class OCP\AppFramework\Http\DataResponse constructor expects T of OCP\AppFramework\Http\DataResponseType, array<string, int|true> given.

Check failure on line 119 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Method OCA\Files_Retention\Controller\APIController::addRetention() should return OCP\AppFramework\Http\DataResponse<201, array{id: int<1, max>, tagid: int<1, max>, timeunit: 0|1|2|3, timeamount: int<1, max>, timeafter: 0|1, hasJob: bool}, array{}>|OCP\AppFramework\Http\DataResponse<400, array{error: 'tagid'|'timeafter'|'timeamount'|'timeunit'}, array{}> but returns OCP\AppFramework\Http\DataResponse<201, OCP\AppFramework\Http\DataResponseType, array{}>.
'id' => $id,
'tagid' => $tagid,
'timeunit' => $timeunit,
Expand All @@ -140,12 +130,12 @@
* 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{}>
*
* 204: Retention rule deleted
* 404: Retention rule not found
*/
public function deleteRetention(int $id): DataResponse {

Check failure on line 138 in lib/Controller/APIController.php

View workflow job for this annotation

GitHub Actions / static-phpstan-analysis

Type array in generic type OCP\AppFramework\Http\DataResponse<int, array, array> in PHPDoc tag @return is not subtype of template type T of OCP\AppFramework\Http\DataResponseType of class OCP\AppFramework\Http\DataResponse.
$qb = $this->db->getQueryBuilder();

// Fetch tag_id
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#'
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