diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f0506cdab..284fbac46 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,6 +32,30 @@ jobs: - "8.3" - "8.4" - "8.5" + php-stan: + name: PHPStan code quality checks + runs-on: ubuntu-24.04 + steps: + - name: Checkout + uses: actions/checkout@v6 + - name: Show the Composer version + run: ./Build/Scripts/runTests.sh -s composer -- --version + - name: Show the Composer configuration + run: ./Build/Scripts/runTests.sh -s composer config --global --list + - name: Install composer dependencies + run: | + ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -s composerUpdateMax + - name: Run phpstan code quality checks + run: | + ./Build/Scripts/runTests.sh -p ${{ matrix.php-version }} -t ${{matrix.typo3-version}} -s phpstan + strategy: + fail-fast: false + matrix: + include: + - typo3-version: "12.4" + php-version: "8.2" + - typo3-version: "13.4" + php-version: "8.2" code-quality: name: Code quality checks runs-on: ubuntu-24.04 @@ -56,7 +80,6 @@ jobs: - "json:lint" - "php:cs-fixer" - "php:rector" - - "php:stan" - "typoscript:lint" - "xliff:lint" - "yaml:lint" diff --git a/Build/Scripts/runTests.sh b/Build/Scripts/runTests.sh index 2e97d6da6..65c339ce8 100755 --- a/Build/Scripts/runTests.sh +++ b/Build/Scripts/runTests.sh @@ -677,13 +677,15 @@ case ${TEST_SUITE} in SUITE_EXIT_CODE=$? ;; phpstan) - COMMAND="composer check:php:stan" - ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}" + PHPSTAN_CONFIG_FILE="Build/phpstan/TYPO3_${CORE_VERSION}/phpstan.neon" + COMMAND=(php -dxdebug.mode=off .Build/bin/phpstan analyse -c ${PHPSTAN_CONFIG_FILE} --no-progress --no-interaction --memory-limit 4G "$@") + ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name phpstan-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}" SUITE_EXIT_CODE=$? ;; phpstanGenerateBaseline) - COMMAND="composer phpstan:baseline" - ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name composer-command-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} /bin/sh -c "${COMMAND}" + PHPSTAN_CONFIG_FILE="Build/phpstan/TYPO3_${CORE_VERSION}/phpstan.neon" + COMMAND=(php -dxdebug.mode=off .Build/bin/phpstan analyse -c ${PHPSTAN_CONFIG_FILE} --no-progress --no-interaction --memory-limit 4G --allow-empty-baseline --generate-baseline=Build/phpstan/TYPO3_${CORE_VERSION}/phpstan-baseline.neon) + ${CONTAINER_BIN} run ${CONTAINER_COMMON_PARAMS} --name phpstan-baseline-${SUFFIX} -e COMPOSER_CACHE_DIR=.cache/composer -e COMPOSER_ROOT_VERSION=${COMPOSER_ROOT_VERSION} ${IMAGE_PHP} "${COMMAND[@]}" SUITE_EXIT_CODE=$? ;; shellcheck) diff --git a/Build/phpstan/TYPO3_12.4/phpstan-baseline.neon b/Build/phpstan/TYPO3_12.4/phpstan-baseline.neon new file mode 100644 index 000000000..364905f71 --- /dev/null +++ b/Build/phpstan/TYPO3_12.4/phpstan-baseline.neon @@ -0,0 +1,2 @@ +parameters: + ignoreErrors: diff --git a/Build/phpstan/TYPO3_12.4/phpstan.neon b/Build/phpstan/TYPO3_12.4/phpstan.neon new file mode 100644 index 000000000..1b8a6544b --- /dev/null +++ b/Build/phpstan/TYPO3_12.4/phpstan.neon @@ -0,0 +1,6 @@ +includes: + - ../phpstan.neon + - phpstan-baseline.neon + +parameters: + phpVersion: 80100 diff --git a/Build/phpstan/phpstan-baseline.neon b/Build/phpstan/TYPO3_13.4/phpstan-baseline.neon similarity index 76% rename from Build/phpstan/phpstan-baseline.neon rename to Build/phpstan/TYPO3_13.4/phpstan-baseline.neon index 0912191aa..e85bc0fe7 100644 --- a/Build/phpstan/phpstan-baseline.neon +++ b/Build/phpstan/TYPO3_13.4/phpstan-baseline.neon @@ -4,22 +4,22 @@ parameters: message: '#^Method TTN\\Tea\\Domain\\Repository\\TeaRepository\:\:findAllFromAllPages\(\) return type with generic interface TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface does not specify its types\: TKey, TValue$#' identifier: missingType.generics count: 1 - path: ../../Classes/Domain/Repository/TeaRepository.php + path: ../../../Classes/Domain/Repository/TeaRepository.php - message: '#^Method TTN\\Tea\\Domain\\Repository\\TeaRepository\:\:findByOwnerUid\(\) return type with generic interface TYPO3\\CMS\\Extbase\\Persistence\\QueryResultInterface does not specify its types\: TKey, TValue$#' identifier: missingType.generics count: 1 - path: ../../Classes/Domain/Repository/TeaRepository.php + path: ../../../Classes/Domain/Repository/TeaRepository.php - message: '#^Cannot call method getUid\(\) on mixed\.$#' identifier: method.nonObject count: 1 - path: ../../Tests/Functional/Domain/Repository/TeaRepositoryTest.php + path: ../../../Tests/Functional/Domain/Repository/TeaRepositoryTest.php - message: '#^Mixed variable in a `\$result\-\>current\(\)\-\>\.\.\.\(\)` can skip important errors\. Make sure the type is known$#' identifier: typePerfect.noMixedMethodCaller count: 1 - path: ../../Tests/Functional/Domain/Repository/TeaRepositoryTest.php + path: ../../../Tests/Functional/Domain/Repository/TeaRepositoryTest.php diff --git a/Build/phpstan/TYPO3_13.4/phpstan.neon b/Build/phpstan/TYPO3_13.4/phpstan.neon new file mode 100644 index 000000000..f42a58832 --- /dev/null +++ b/Build/phpstan/TYPO3_13.4/phpstan.neon @@ -0,0 +1,7 @@ +includes: + - ../phpstan.neon + - phpstan-baseline.neon + +parameters: + phpVersion: 80200 + diff --git a/Build/phpstan/phpstan.neon b/Build/phpstan/phpstan.neon index a3fdc52ce..829b53b23 100644 --- a/Build/phpstan/phpstan.neon +++ b/Build/phpstan/phpstan.neon @@ -1,13 +1,10 @@ includes: - - phpstan-baseline.neon - ../../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-dangerous-calls.neon - ../../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-execution-calls.neon - ../../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-insecure-calls.neon - ../../.Build/vendor/spaze/phpstan-disallowed-calls/disallowed-loose-calls.neon parameters: - phpVersion: 80100 - level: 9 paths: diff --git a/composer.json b/composer.json index 48f19e8ce..e547c616c 100644 --- a/composer.json +++ b/composer.json @@ -136,13 +136,11 @@ "check:json:lint": "find . ! -path '*/.cache/*' ! -path '*/.Build/*' ! -path '*/node_modules/*' -name '*.json' | xargs -r php .Build/bin/jsonlint -q", "check:php": [ "@check:php:cs-fixer", - "@check:php:lint", - "@check:php:stan" + "@check:php:lint" ], "check:php:cs-fixer": "php-cs-fixer fix --config ./Build/php-cs-fixer/config.php -v --dry-run --diff", "check:php:lint": "parallel-lint *.php Build Classes Configuration Tests", "check:php:rector": "rector process --dry-run --config=./Build/rector/config.php", - "check:php:stan": "phpstan --no-progress -v --configuration=Build/phpstan/phpstan.neon", "check:static": [ "@check:composer:normalize", "@check:composer:unused", @@ -150,7 +148,6 @@ "@check:php:lint", "@check:composer:psr-verify", "@check:php:rector", - "@check:php:stan", "@check:php:cs-fixer", "@check:typoscript:lint", "@check:xliff:lint", @@ -177,7 +174,6 @@ ], "fix:php:cs-fixer": "php-cs-fixer fix --config ./Build/php-cs-fixer/config.php", "fix:php:rector": "rector process --config=./Build/rector/config.php", - "phpstan:baseline": "phpstan --generate-baseline=Build/phpstan/phpstan-baseline.neon --allow-empty-baseline --configuration=Build/phpstan/phpstan.neon", "prepare-release": [ "rm -rf .Build", "rm -rf .ddev", @@ -208,7 +204,6 @@ "check:php:lint": "Lints the PHP files for syntax errors.", "check:php:mess": "Runs PHP mess detection.", "check:php:rector": "Checks for code for changes by Rector.", - "check:php:stan": "Checks the PHP types using PHPStan.", "check:static": "Runs all static code checks (syntax, style, types).", "check:tests:create-directories": "Creates the directories required to smoothely run the functional tests.", "check:tests:functional": "Runs the functional tests.", @@ -222,7 +217,6 @@ "fix:php": "Runs all fixers for the PHP code.", "fix:php:cs-fixer": "Fixes the code style with PHP-CS-Fixer.", "fix:php:rector": "Updates the code with Rector.", - "phpstan:baseline": "Updates the PHPStan baseline file to match the code.", "prepare-release": "Removes development-only files in preparation of a TER release." } }