From d364a0aa1d6859305a68960cb0b52b9a51632377 Mon Sep 17 00:00:00 2001 From: Christian Leucht Date: Wed, 18 Dec 2024 15:27:28 +0100 Subject: [PATCH] static-analysis-php // init commit to support PHPStan. --- .github/workflows/static-analysis-php.yml | 10 ++++++++++ docs/php.md | 13 +++++++++++-- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis-php.yml b/.github/workflows/static-analysis-php.yml index 2a544dfd..8c5be3fe 100644 --- a/.github/workflows/static-analysis-php.yml +++ b/.github/workflows/static-analysis-php.yml @@ -18,6 +18,11 @@ on: default: '--output-format=github --no-cache' required: false type: string + PHPSTAN_ARGS: + description: Set of arguments passed to PHPStan. + default: ' --no-progress --memory-limit=1G' + required: false + type: string secrets: COMPOSER_AUTH_JSON: description: Authentication for privately hosted packages and repositories as a JSON formatted object. @@ -63,4 +68,9 @@ jobs: composer-options: ${{ inputs.COMPOSER_ARGS }} - name: Run Psalm + if: ${{ hashFiles('psalm.xml') }} run: ./vendor/bin/psalm --php-version="${{ inputs.PHP_VERSION }}" ${{ inputs.PSALM_ARGS }} + + - name: Run PHPStan + if: ${{ hashFiles('phpstan.neon.dist, phpstan.neon, phpstan.dist.neon') }} + run: ./vendor/bin/phpstan ${{ inputs.PSALM_ARGS }} \ No newline at end of file diff --git a/docs/php.md b/docs/php.md index 3cf89c1d..c078d0f6 100644 --- a/docs/php.md +++ b/docs/php.md @@ -61,8 +61,16 @@ versions. ## Static code analysis -This workflow runs [Psalm](https://psalm.dev/). It does so by executing the binary in the -`./vendor/bin/` folder. +This workflow runs [Psalm](https://psalm.dev/) or [PHPStan](https://phpstan.org/) by looking for the configuration files in your repository root folder. + +It does so by executing the binary in the `./vendor/bin/` folder. + +**Supported configuration files:** + +| tool | file(s) | +|-----------|----------------------------------------------------------| +| `psalm` | `psalm.xml` | +| `phpstan` | `phpstan.neon.dist`, `phpstan.neon`, `phpstan.dist.neon` | **Simplest possible example:** @@ -85,6 +93,7 @@ jobs: | `PHP_VERSION` | `'8.2'` | PHP version with which the scripts are executed | | `COMPOSER_ARGS` | `'--prefer-dist'` | Set of arguments passed to Composer | | `PSALM_ARGS` | `'--output-format=github --no-cache'` | Set of arguments passed to Psalm | +| `PSALM_ARGS` | `'--output-format=github --no-cache'` | Set of arguments passed to PHPStan | #### Secrets