From 375bfdc4d43774ff508f7a53fc24d09916f2b80b Mon Sep 17 00:00:00 2001 From: Nathan Boiron Date: Sun, 26 Nov 2023 17:17:52 +0100 Subject: [PATCH] mise en place de PHPStan dans la CI --- .github/workflows/ci.yml | 59 ++++++++++++++++++++++++++++++---------- Makefile | 5 +++- composer.json | 6 ++-- composer.lock | 7 +++-- phpstan.neon | 27 ++++++++++++++++++ 5 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 phpstan.neon diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8be984c43..4fee11bc7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -7,20 +7,20 @@ jobs: unit: name: "Unit tests" runs-on: ubuntu-20.04 - + strategy: fail-fast: false matrix: php: ["5.6", "7.0"] - + steps: - uses: actions/checkout@v2 - + - name: Setup PHP with tools uses: shivammathur/setup-php@v2 with: php-version: '${{ matrix.php }}' - + - name: Composer - Get Cache Directory id: composer-cache run: echo "::set-output name=dir::$(composer config cache-files-dir)" @@ -54,20 +54,17 @@ jobs: with: php-version: '5.6' - - name: Composer - Get Cache Directory + - name: Get Composer Cache Directory id: composer-cache - run: echo "::set-output name=dir::$(composer config cache-files-dir)" + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT - - uses: actions/cache@v1 - id: cache-composer + - uses: actions/cache@v3 with: path: ${{ steps.composer-cache.outputs.dir }} - key: composer-php.5.6-${{ github.sha }} - restore-keys: composer-php.5.6- - - - name: Composer - Create cache directory - run: mkdir -p /home/runner/.composer/cache - if: steps.cache-composer.outputs.cache-hit != 'true' + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- - name: CS fixer prerequisites run: make configs/application/config.php @@ -78,6 +75,40 @@ jobs: - name: Tests - CS Fixer run: ./bin/php-cs-fixer fix --dry-run -vv + phpstan: + name: "PHPStan" + runs-on: ubuntu-20.04 + + steps: + - uses: actions/checkout@v4 + + - name: Setup PHP with tools + uses: shivammathur/setup-php@v2 + with: + php-version: '8.2' + tools: phpstan + + - name: Get Composer Cache Directory + id: composer-cache + run: | + echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-composer- + + - name: Prerequisites + run: make configs/application/config.php + + - name: Composer install + run: composer install --no-scripts --ignore-platform-req=php + + - name: PHPStan + run: phpstan analyse + functional: name: "Functional tests" runs-on: ubuntu-20.04 diff --git a/Makefile b/Makefile index c41857671..eddc535eb 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,7 @@ CURRENT_UID ?= $(shell id -u) DOCKER_UP_OPTIONS ?= -.PHONY: install docker-up docker-stop docker-down test hooks vendors db-seed db-migrations reset-db init console +.PHONY: install docker-up docker-stop docker-down test hooks vendors db-seed db-migrations reset-db init console phpstan install: vendors @@ -109,3 +109,6 @@ db-seed: console: CURRENT_UID=$(CURRENT_UID) docker-compose run --rm cliphp bash + +phpstan: + docker run -v $(shell pwd):/app --rm ghcr.io/phpstan/phpstan diff --git a/composer.json b/composer.json index 88b16447a..87a6512f3 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "dms/meetup-api-client": "^2.3", "robmorgan/phinx": "^0.9.2", "presta/sitemap-bundle": "^1.5", - "setasign/fpdf": "1.53", + "setasign/fpdf": "1.6", "ezyang/htmlpurifier": "^4.10", "phpoffice/phpspreadsheet": "^1.6", "phpmailer/phpmailer": "5.2.9", @@ -111,9 +111,9 @@ "type": "package", "package": { "name": "setasign/fpdf", - "version": "1.53", + "version": "1.6", "dist": { - "url": "http://www.fpdf.org/en/dl.php?v=153&f=zip", + "url": "http://www.fpdf.org/en/dl.php?v=16&f=zip", "type": "zip" }, "autoload": { diff --git a/composer.lock b/composer.lock index 476ba1b73..8b6b9d2fc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b02a5bda029a7c3d77208e67833d4254", + "content-hash": "4f19213a494df80627e21021df4e0e44", "packages": [ { "name": "algolia/algoliasearch-client-php", @@ -4098,10 +4098,10 @@ }, { "name": "setasign/fpdf", - "version": "1.53", + "version": "1.6", "dist": { "type": "zip", - "url": "http://www.fpdf.org/en/dl.php?v=153&f=zip" + "url": "http://www.fpdf.org/en/dl.php?v=16&f=zip" }, "type": "library", "autoload": { @@ -6161,6 +6161,7 @@ "ext-json": "*", "ext-dom": "*", "ext-libxml": "*", + "ext-openssl": "*", "ext-curl": "*" }, "platform-dev": [], diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..37677585e --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,27 @@ +parameters: + phpVersion: 70400 # PHP 7.4 + level: 1 + paths: + - sources + scanFiles: + - dependencies/magpierss/extlib/Snoopy.class.inc + - dependencies/magpierss/rss_cache.inc + - dependencies/magpierss/rss_fetch.inc + - dependencies/magpierss/rss_parse.inc + - dependencies/magpierss/rss_utils.inc + excludePaths: + analyse: + # Ces fichiers utilisent des alias de classes + - sources/AppBundle/Twig/AssetsExtension.php + - sources/AppBundle/Twig/TwigExtension.php + # Ce fichier est impossible à analyser, des variables globales, du eval, etc. + - sources/Afup/Utils/Configuration.php + ignoreErrors: + # Variable globale + - + message: '#Undefined variable: \$configuration#' + path: sources/Afup/Utils/SymfonyKernel.php + # Variable globale + - + message: '#Undefined variable: \$smarty#' + path: sources/AppBundle/Controller/LegacyController.php