core/scripts/dev/commit-code-check.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/core/scripts/dev/commit-code-check.sh b/core/scripts/dev/commit-code-check.sh index 40a0cd733f..e9d0f29327 100755 --- a/core/scripts/dev/commit-code-check.sh +++ b/core/scripts/dev/commit-code-check.sh @@ -116,6 +116,12 @@ # The site root directory is 3 levels up from where the script is located. DRUPAL_ROOT=$(dirname $(dirname $(dirname $SCRIPT_ABS_PATH))) +# Detect whether we're testing Drupal core or not. +IS_DRUPAL_CORE=0 +if [[ "$TOP_LEVEL" == "$DRUPAL_ROOT" ]]; then + IS_DRUPAL_CORE=1 +fi + # This variable will be set to one when the file core/phpcs.xml.dist is changed. PHPCS_XML_DIST_FILE_CHANGED=0 @@ -226,22 +232,25 @@ fi cd "$TOP_LEVEL" -exit 0 - # Add a separator line to make the output easier to read. printf "\n" printf -- '-%.0s' {1..100} printf "\n" -# Run PHPStan on all files on DrupalCI or when phpstan files are changed. +# Run PHPStan on all files on DrupalCI, when phpstan files are changed or when not checking Drupal core. # APCu is disabled to ensure that the composer classmap is not corrupted. -if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]] || [[ "$DRUPALCI" == "1" ]]; then +if [[ $PHPSTAN_DIST_FILE_CHANGED == "1" ]] || [[ "$DRUPALCI" == "1" ]] || [[ "$IS_DRUPAL_CORE" == "0" ]]; 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" + PHPSTAN_CONFIGURATION="$DRUPAL_ROOT/core/phpstan.neon.dist" + # Detect the presence of a phpstan.neon.dist in the current project, or fall back to Drupal core's. + if [[ "$IS_DRUPAL_CORE" == "0" ]] && [[ -f "$TOP_LEVEL/phpstan.neon.dist" ]]; then + PHPSTAN_CONFIGURATION="$TOP_LEVEL/phpstan.neon.dist" + fi + php -d apc.enabled=0 -d apc.enable_cli=0 $DRUPAL_ROOT/vendor/bin/phpstan analyze --no-progress --configuration="$PHPSTAN_CONFIGURATION" $TOP_LEVEL else # Only run PHPStan on changed files locally. 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 + php -d apc.enabled=0 -d apc.enable_cli=0 $DRUPAL_ROOT/vendor/bin/phpstan analyze --no-progress --configuration="$DRUPAL_ROOT/core/phpstan-partial.neon" $ABS_FILES fi if [ "$?" -ne "0" ]; then @@ -252,6 +261,8 @@ printf "\nPHPStan: ${green}passed${reset}\n" fi +exit 0 + # Add a separator line to make the output easier to read. printf "\n" printf -- '-%.0s' {1..100}