From fe307a0fee0b76d5b2115955e6c33d6803233290 Mon Sep 17 00:00:00 2001 From: catch Date: Tue, 18 Jan 2022 09:34:31 +0000 Subject: Issue #3178534 by mondrake, klausi, alexpott, longwave, mallezie, Taran2L, mglaman, Spokje, kim.pepper, daffie, andypost, neclimdul, xjm, Gábor Hojtsy, cmlara: Start running PHPStan on Drupal core (level 0) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/scripts/dev/commit-code-check.sh | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) (limited to 'core/scripts/dev/commit-code-check.sh') diff --git a/core/scripts/dev/commit-code-check.sh b/core/scripts/dev/commit-code-check.sh index e5cba556954c..9660d8084b2b 100755 --- a/core/scripts/dev/commit-code-check.sh +++ b/core/scripts/dev/commit-code-check.sh @@ -11,6 +11,7 @@ # - File modes. # - No changes to core/node_modules directory. # - PHPCS checks PHP and YAML files. +# - PHPStan checks PHP files. # - ESLint checks JavaScript and YAML files. # - Checks .es6.js and .js files are equivalent. # - Stylelint checks CSS files. @@ -110,6 +111,10 @@ TOP_LEVEL=$(git rev-parse --show-toplevel) # This variable will be set to one when the file core/phpcs.xml.dist is changed. PHPCS_XML_DIST_FILE_CHANGED=0 +# This variable will be set to one when the files core/phpstan-baseline.neon or +# core/phpstan.neon.dist are changed. +PHPSTAN_DIST_FILE_CHANGED=0 + # This variable will be set to one when one of the eslint config file is # changed: # - core/.eslintrc.passing.json @@ -126,6 +131,10 @@ for FILE in $FILES; do PHPCS_XML_DIST_FILE_CHANGED=1; fi; + if [[ $FILE == "core/phpstan-baseline.neon" || $FILE == "core/phpstan.neon.dist" ]]; then + PHPSTAN_DIST_FILE_CHANGED=1; + fi; + if [[ $FILE == "core/.eslintrc.json" || $FILE == "core/.eslintrc.passing.json" || $FILE == "core/.eslintrc.jquery.json" ]]; then ESLINT_CONFIG_PASSING_FILE_CHANGED=1; fi; @@ -181,6 +190,28 @@ printf "\n" printf -- '-%.0s' {1..100} printf "\n" +# Run PHPStan on all files in one go for better performance. APCu is disabled to +# ensure that the composer classmap is not corrupted. +if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]]; then + printf "\nRunning PHPStan on *all* files.\n" + php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration="$TOP_LEVEL/core/phpstan.neon.dist" +else + printf "\nRunning PHPStan on changed files.\n" + php -d apc.enabled=0 -d apc.enable_cli=0 vendor/bin/phpstan analyze --no-progress --configuration="$TOP_LEVEL/core/phpstan-partial.neon" $ABS_FILES +fi +if [ "$?" -ne "0" ]; then + # If there are failures set the status to a number other than 0. + FINAL_STATUS=1 + printf "\nPHPStan: ${red}failed${reset}\n" +else + printf "\nPHPStan: ${green}passed${reset}\n" +fi + +# Add a separator line to make the output easier to read. +printf "\n" +printf -- '-%.0s' {1..100} +printf "\n" + # When the file core/phpcs.xml.dist has been changed, then PHPCS must check all files. if [[ $PHPCS_XML_DIST_FILE_CHANGED == "1" ]]; then # Test all files with phpcs rules. -- cgit v1.2.3