Skip to content

Commit

Permalink
build: Add psalm
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin committed Jan 7, 2025
1 parent e9f47a7 commit d4213b4
Show file tree
Hide file tree
Showing 8 changed files with 2,261 additions and 2 deletions.
82 changes: 82 additions & 0 deletions .github/workflows/psalm-matrix.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# 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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

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

- name: Check enforcement of minimum PHP version ${{ steps.versions.outputs.php-min }} in psalm.xml
run: grep 'phpVersion="${{ steps.versions.outputs.php-min }}' psalm.xml

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@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false

- 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 remove nextcloud/ocp --dev
composer i
- name: Install dependencies # zizmor: ignore[template-injection]
run: composer 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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
/.php_cs.cache
/build
/node_modules
/vendor/
vendor/
.idea/
.php-cs-fixer.cache
6 changes: 6 additions & 0 deletions REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,9 @@ path = ["l10n/**.js", "l10n/**.json", "js/**.js.map", "js/**.js", "js/**.mjs", "
precedence = "aggregate"
SPDX-FileCopyrightText = "2019 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"

[[annotations]]
path = ["psalm.xml", "psalm-baseline.xml"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2024 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "AGPL-3.0-or-later"
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
"lint": "find . -name \\*.php -not -path './vendor/*' -print0 | xargs -0 -n1 php -l",
"cs:check": "php-cs-fixer fix --dry-run --diff",
"cs:fix": "php-cs-fixer fix",
"test:unit": "echo 'Only testing installation of the app'"
"test:unit": "echo 'Only testing installation of the app'",
"psalm": "psalm --threads=$(nproc) --no-cache"
},
"require-dev": {
"nextcloud/coding-standard": "^1.2.1",
Expand Down
37 changes: 37 additions & 0 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<file src="lib/AppInfo/Application.php">
<UndefinedClass>
<code><![CDATA[LoadAdditionalScriptsEvent]]></code>
</UndefinedClass>
</file>
<file src="lib/Listeners/FilesLoadAdditionalScriptsListener.php">
<MissingTemplateParam>
<code><![CDATA[IEventListener]]></code>
</MissingTemplateParam>
<UndefinedClass>
<code><![CDATA[LoadAdditionalScriptsEvent]]></code>
</UndefinedClass>
</file>
<file src="lib/Service/RecentlyCommentedFilesSource.php">
<MissingDependency>
<code><![CDATA[$this->rootFolder]]></code>
<code><![CDATA[IRootFolder]]></code>
<code><![CDATA[IRootFolder]]></code>
</MissingDependency>
</file>
<file src="lib/Service/RecentlyEditedFilesSource.php">
<MissingDependency>
<code><![CDATA[$rootFolder]]></code>
<code><![CDATA[$rootFolder]]></code>
<code><![CDATA[IRootFolder]]></code>
</MissingDependency>
</file>
<file src="lib/Service/RecentlySharedFilesSource.php">
<MissingDependency>
<code><![CDATA[$this->rootFolder]]></code>
<code><![CDATA[IRootFolder]]></code>
<code><![CDATA[IRootFolder]]></code>
</MissingDependency>
</file>
</files>
22 changes: 22 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0"?>
<psalm
errorLevel="4"
phpVersion="8.1"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
errorBaseline="psalm-baseline.xml"
findUnusedBaselineEntry="true"
findUnusedCode="false"
>
<projectFiles>
<directory name="lib" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<extraFiles>
<directory name="vendor" />
</extraFiles>
</psalm>
10 changes: 10 additions & 0 deletions vendor-bin/psalm/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"config": {
"platform": {
"php": "8.1"
}
},
"require-dev": {
"vimeo/psalm": "^5.26"
}
}
Loading

0 comments on commit d4213b4

Please sign in to comment.