Skip to content

Commit

Permalink
Merge pull request #1004 from nextcloud/psalm
Browse files Browse the repository at this point in the history
ci(psalm): Add psalm CI
  • Loading branch information
nickvergessen authored Oct 23, 2024
2 parents f578b17 + 18e8e10 commit 9b4773f
Show file tree
Hide file tree
Showing 22 changed files with 2,781 additions and 97 deletions.
41 changes: 0 additions & 41 deletions .github/workflows/lint-eslint-when-unrelated.yml

This file was deleted.

45 changes: 0 additions & 45 deletions .github/workflows/node-when-unrelated.yml

This file was deleted.

73 changes: 73 additions & 0 deletions .github/workflows/psalm-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# 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: 2022-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT

name: Static analysis

on: pull_request

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

jobs:
matrix:
runs-on: ubuntu-latest-low
outputs:
ocp-matrix: ${{ steps.versions.outputs.ocp-matrix }}
steps:
- name: Checkout app
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Get version matrix
id: versions
uses: icewind1991/nextcloud-version-matrix@58becf3b4bb6dc6cef677b15e2fd8e7d48c0908f # v1.3.1

static-analysis:
runs-on: ubuntu-latest
needs: matrix
strategy:
# do not stop on another job's failure
fail-fast: false
matrix: ${{ fromJson(needs.matrix.outputs.ocp-matrix) }}

name: static-psalm-analysis ${{ matrix.ocp-version }}
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Set up php${{ matrix.php-versions }}
uses: shivammathur/setup-php@c541c155eee45413f5b09a52248675b1a2575231 # v2.31.1
with:
php-version: ${{ matrix.php-versions }}
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 bin psalm remove nextcloud/ocp --dev
composer i
- name: Overwrite nextcloud/OCP version
run: composer bin psalm require --dev 'nextcloud/ocp:${{ matrix.ocp-version }}' --ignore-platform-reqs --with-dependencies

- name: Run coding standards check
run: composer run psalm -- --threads=1 --monochrome --no-progress --output-format=github

summary:
runs-on: ubuntu-latest-low
needs: static-analysis

if: always()

name: static-psalm-analysis-summary

steps:
- name: Summary status
run: if ${{ needs.static-analysis.result != 'success' }}; then exit 1; fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,6 @@ translationfiles

# Testing
/tests/.phpunit.result.cache

# Development
/vendor-bin/*/vendor
4 changes: 2 additions & 2 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<description><![CDATA[Requires users to accept the terms of service before accessing data.
This product includes GeoLite2 data created by MaxMind, available from [maxmind.com](http://www.maxmind.com)]]></description>

<version>3.1.0</version>
<version>4.0.0</version>
<licence>agpl</licence>
<author>Joas Schilling</author>

Expand All @@ -33,7 +33,7 @@ This product includes GeoLite2 data created by MaxMind, available from [maxmind.
<screenshot>https://github.com/nextcloud/terms_of_service/raw/master/docs/notification-and-settings.png</screenshot>

<dependencies>
<nextcloud min-version="27" max-version="31" />
<nextcloud min-version="28" max-version="30" />
</dependencies>

<repair-steps>
Expand Down
23 changes: 21 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"autoload": {
"psr-4": {
"OCA\\TermsOfService\\": "lib/"
}
},
"config": {
"classmap-authoritative": true,
"allow-plugins": {
"bamarni/composer-bin-plugin": true
},
"autoloader-suffix": "TermsOfService",
"optimize-autoloader": true,
"platform": {
"php": "8.0"
"php": "8.0.2"
},
"sort-packages": true
},
Expand All @@ -12,11 +20,22 @@
"geoip2/geoip2": "~2.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"phpunit/phpunit": "^9.5",
"roave/security-advisories": "dev-latest"
},
"scripts": {
"bin": "echo 'bin not installed'",
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"post-install-cmd": [
"@composer bin all install --ansi",
"composer dump-autoload"
],
"post-update-cmd": [
"@composer bin all update --ansi",
"composer dump-autoload"
],
"psalm": "psalm --no-cache --threads=$(nproc)",
"test:unit": "vendor/bin/phpunit --color -c tests/phpunit.xml"
}
}
59 changes: 58 additions & 1 deletion composer.lock

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

4 changes: 3 additions & 1 deletion lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public function boot(IBootContext $context): void {
}

public function registerFrontend(IRequest $request, IConfig $config, IUserSession $userSession): void {
/** @psalm-suppress UndefinedClass */
if (!\OC::$CLI) {
if ($userSession->getUser() instanceof IUser
&& strpos($request->getPathInfo(), '/s/') !== 0
Expand All @@ -96,12 +97,13 @@ public function addStorageWrapper(): void {

/**
* @param string $mountPoint
* @param IStorage|Wrapper $storage
* @param IStorage $storage
*
* @return StorageWrapper|IStorage
* @throws Exception
*/
public function addStorageWrapperCallback(string $mountPoint, IStorage $storage): IStorage {
/** @psalm-suppress UndefinedClass */
if (!\OC::$CLI) {
try {
return new StorageWrapper(
Expand Down
2 changes: 1 addition & 1 deletion lib/Checker.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private function matchCidr(string $ip, string $range): bool {
$subnet = inet_pton($subnet);
$ip = inet_pton($ip);

$binMask = str_repeat("f", $bits / 4);
$binMask = str_repeat("f", (int)($bits / 4));
switch ($bits % 4) {
case 0:
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Db/Mapper/SignatoryMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* @method Signatory mapRowToEntity(array $row)
* @template-extends QBMapper<Signatory>
*/
class SignatoryMapper extends QBMapper {
const TABLENAME = 'termsofservice_sigs';
Expand Down
1 change: 1 addition & 0 deletions lib/Db/Mapper/TermsMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

/**
* @method Terms mapRowToEntity(array $row)
* @template-extends QBMapper<Terms>
*/
class TermsMapper extends QBMapper {
const TABLENAME = 'termsofservice_terms';
Expand Down
5 changes: 2 additions & 3 deletions lib/Filesystem/CacheWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@
use OC\Files\Cache\Wrapper\CacheWrapper as Wrapper;
use OCP\Constants;
use OCP\Files\Cache\ICache;
use OCP\Files\ForbiddenException;
use OCP\Files\Storage\IStorage;

class CacheWrapper extends Wrapper {
class CacheWrapper extends Wrapper {
/** @var Helper */
private $helper;
/** @var StorageWrapper*/
/** @var StorageWrapper */
protected $storage;
/** @var int */
protected $mask;
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/RegistrationIntegration.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
use OCP\IUser;
use OCP\Util;

/**
* @template-implements IEventListener<ShowFormEvent|ValidateFormEvent|PassedFormEvent>
*/
class RegistrationIntegration implements IEventListener {

/** @var SignatoryMapper */
Expand Down
3 changes: 3 additions & 0 deletions lib/Listener/UserDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
use OCP\EventDispatcher\IEventListener;
use OCP\User\Events\UserDeletedEvent;

/**
* @template-implements IEventListener<UserDeletedEvent>
*/
class UserDeletedListener implements IEventListener {

/** @var SignatoryMapper */
Expand Down
2 changes: 1 addition & 1 deletion lib/Migration/Version1000Date20220111180247.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt

$table = $schema->getTable('termsofservice_sigs');
$column = $table->getColumn('user_id');
if (!$column->getLength() !== 64) {
if ($column->getLength() !== 64) {
$column->setLength(64);
return $schema;
}
Expand Down
Loading

0 comments on commit 9b4773f

Please sign in to comment.