summaryrefslogtreecommitdiffstatshomepage
path: root/core/scripts/dev/commit-code-check.sh
diff options
context:
space:
mode:
authorcatch <catch@35733.no-reply.drupal.org>2022-01-18 09:34:31 +0000
committercatch <catch@35733.no-reply.drupal.org>2022-01-18 10:08:49 +0000
commitfe307a0fee0b76d5b2115955e6c33d6803233290 (patch)
tree02a69deab119a207b5bb89fbd161bcd2a97ba19f /core/scripts/dev/commit-code-check.sh
parent30523436ce73efc4588ed191232ae516b5ad9c76 (diff)
downloaddrupal-fe307a0fee0b76d5b2115955e6c33d6803233290.tar.gz
drupal-fe307a0fee0b76d5b2115955e6c33d6803233290.zip
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)
Diffstat (limited to 'core/scripts/dev/commit-code-check.sh')
-rwxr-xr-xcore/scripts/dev/commit-code-check.sh31
1 files changed, 31 insertions, 0 deletions
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.