From 444b194019e32a2340e815e8514fafc67ac5f6ef Mon Sep 17 00:00:00 2001 From: JiaJia Ji Date: Mon, 12 Dec 2022 14:44:03 +0100 Subject: [PATCH] [Task]: Setup Phpstan #4 (#4) * Task: Setup PHPStan * Task: Add phpstan require-dev * Task: fix handleResponse phpdoc * Task: add/fix phpdoc params and return * Apply php-cs-fixer changes * fix missing null in phpdocblock Co-authored-by: kingjia90 --- .github/ci/files/.env | 1 + .../ci/scripts/setup-pimcore-environment.sh | 5 ++ .github/workflows/static-analysis.yml | 50 +++++++++++++++++++ composer.json | 3 ++ phpstan-baseline.neon | 2 + phpstan-bootstrap.php | 19 +++++++ phpstan.neon | 8 +++ src/PaymentManager/Payment/Klarna.php | 19 +++++-- 8 files changed, 102 insertions(+), 5 deletions(-) create mode 100644 .github/ci/files/.env create mode 100755 .github/ci/scripts/setup-pimcore-environment.sh create mode 100644 .github/workflows/static-analysis.yml create mode 100644 phpstan-baseline.neon create mode 100644 phpstan-bootstrap.php create mode 100644 phpstan.neon diff --git a/.github/ci/files/.env b/.github/ci/files/.env new file mode 100644 index 0000000..4250748 --- /dev/null +++ b/.github/ci/files/.env @@ -0,0 +1 @@ +APP_ENV=test \ No newline at end of file diff --git a/.github/ci/scripts/setup-pimcore-environment.sh b/.github/ci/scripts/setup-pimcore-environment.sh new file mode 100755 index 0000000..95116c5 --- /dev/null +++ b/.github/ci/scripts/setup-pimcore-environment.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -eu -o xtrace + +cp .github/ci/files/.env . \ No newline at end of file diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000..3050e5e --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,50 @@ +name: "Static Analysis" + +on: + pull_request: + branches: + - "[0-9]+.[0-9]+" + - "[0-9]+.x" + push: + branches: + - "[0-9]+.[0-9]+" + - "[0-9]+.x" + +jobs: + static-analysis-phpstan: + name: "Static Analysis with PHPStan" + runs-on: "ubuntu-20.04" + strategy: + matrix: + include: + - { php-version: 8.0, database: "mariadb:10.7", pimcore_version: "", dependencies: lowest, experimental: false } + - { php-version: 8.1, database: "mariadb:10.7", pimcore_version: "", dependencies: highest, experimental: false } + steps: + - name: "Checkout code" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + + - name: "Setup Pimcore environment" + run: | + .github/ci/scripts/setup-pimcore-environment.sh + +# - name: "Update Pimcore version" +# env: +# PIMCORE_VERSION: "${{ matrix.pimcore_version }}" +# run: | +# if [ ! -z "$PIMCORE_VERSION" ]; then +# composer require --no-update pimcore/pimcore:"${PIMCORE_VERSION}" +# fi + + - name: "Install dependencies with Composer" + uses: "ramsey/composer-install@v2" + with: + dependency-versions: "${{ matrix.dependencies }}" + + - name: "Run a static analysis with phpstan/phpstan" + run: "vendor/bin/phpstan analyse ${{ matrix.phpstan_args }} -c phpstan.neon --memory-limit=-1" \ No newline at end of file diff --git a/composer.json b/composer.json index 0759aca..df3ff1a 100644 --- a/composer.json +++ b/composer.json @@ -10,6 +10,9 @@ "klarna/checkout": "^3.0.0", "pimcore/pimcore": "^10.0.0" }, + "require-dev": { + "phpstan/phpstan": "^1.9" + }, "autoload": { "psr-4": { "Pimcore\\Bundle\\EcommerceFrameworkBundle\\": "src/" diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon new file mode 100644 index 0000000..364905f --- /dev/null +++ b/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: diff --git a/phpstan-bootstrap.php b/phpstan-bootstrap.php new file mode 100644 index 0000000..5aa99e2 --- /dev/null +++ b/phpstan-bootstrap.php @@ -0,0 +1,19 @@ +