Commit 5849597f authored by Travis Carden's avatar Travis Carden Committed by Ted Bowman
Browse files

Issue #3305312 by TravisCarden: Add scripts to run PHPCS and PHPCBF

parent 210fea30
Loading
Loading
Loading
Loading
+8 −0
Original line number Diff line number Diff line
@@ -24,5 +24,13 @@
    "platform": {
      "php": "7.4.0"
    }
  },
  "scripts": {
    "phpcbf": "scripts/phpcbf.sh",
    "phpcs": "scripts/phpcs.sh"
  },
  "scripts-descriptions": {
    "phpcbf": "Automatically fixes standards violations where possible.",
    "phpcs": "Checks code for standards compliance."
  }
}

scripts/phpcbf.sh

0 → 100755
+39 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash

# NAME
#     phpcbf.sh - Automatically fixe standards violations where possible.
#
# SYNOPSIS
#     bash phpcbf.sh
#
# DESCRIPTION
#     Fix code compliance with Drupal core coding standards using PHP Code
#     Beautifier and Fixer (PHPCBF).
#
#     It is assumed that this module is inside a Drupal core installation, in
#     modules or modules/contrib. See setup_local_dev.sh.

cd "$(dirname "$0")" || exit 0;

## Find PHPCBF in Drupal core. Check up to three directories up.
DIR=$(pwd)
for i in {0..3}; do
  DIR=$(dirname "$DIR")
  PHPCBF_BIN="$DIR/vendor/bin/phpcbf"
  PHPCS_CONFIG="$DIR/core/phpcs.xml.dist"
  if test -f "$PHPCBF_BIN"; then
    break
  fi
done

# Exit if PHPCBF can't be found.
if test ! -f "$PHPCBF_BIN"; then
  echo "Could not find PHPCBF. Are you inside a Drupal site's 'modules' directory?"
  exit 1
fi

# Run PHPCBF on the module directory.
php "$PHPCBF_BIN" \
  --colors \
  --standard="$PHPCS_CONFIG" \
  "$(cd .. && pwd)"

scripts/phpcs.sh

0 → 100755
+39 −0
Original line number Diff line number Diff line
#!/usr/bin/env bash

# NAME
#     phpcs.sh - Check code for standards compliance.
#
# SYNOPSIS
#     bash phpcs.sh
#
# DESCRIPTION
#     Check for compliance with Drupal core coding standards using
#     PHP_CodeSniffer (PHPCS).
#
#     It is assumed that this module is inside a Drupal core installation, in
#     modules or modules/contrib. See setup_local_dev.sh.

cd "$(dirname "$0")" || exit 0;

## Find PHPCS in Drupal core. Check up to three directories up.
DIR=$(pwd)
for i in {0..3}; do
  DIR=$(dirname "$DIR")
  PHPCS_BIN="$DIR/vendor/bin/phpcs"
  PHPCS_CONFIG="$DIR/core/phpcs.xml.dist"
  if test -f "$PHPCS_BIN"; then
    break
  fi
done

# Exit if PHPCS can't be found.
if test ! -f "$PHPCS_BIN"; then
  echo "Could not find PHPCS. Are you inside a Drupal site's 'modules' directory?"
  exit 1
fi

# Run PHPCS on the module directory.
php "$PHPCS_BIN" \
  --colors \
  --standard="$PHPCS_CONFIG" \
  "$(cd .. && pwd)"