PHP Code Sniffer

phpcs and phpcbf are readily available in the cli container. Both Drupal Coding Standards and WordPress Coding Standards have been installed and are ready to use.

Using as an Addon

We have converted this into a Docksal Addon which can be installed running the addon subcommand.

fin addon install phpcs

This will enable the following to run:

# Running PHPCS
fin phpcs cs docroot/sites/all/modules/custom
# Running PHPCBF
fin phpcs cbf docroot/sites/all/modules/custom

Standards currently installed are

  • WordPress
    • WordPress-Core
    • WordPress-Extra
    • WordPress-Docs
  • Drupal
    • Drupal
    • DrupalPractice

Using Directly

Instead of installing an addon, you can use phpcs/phpcbf directly every time. The following commands below can be run anywhere from within your project’s folder:

With Drupal

fin run phpcs \
    --standards="Drupal,DrupalPractice" -n \
    --extensions="php,module,inc,install,test,profile,theme" \
    --ignore="*.features.*,*.pages*.inc" \
    docroot/sites/all/modules/custom
fin run phpcbf \
    --standards="Drupal,DrupalPractice" -n \
    --extensions="php,module,inc,install,test,profile,theme" \
    --ignore="*.features.*,*.pages*.inc" \
    docroot/sites/all/modules/custom

With WordPress

fin run phpcs \
    --standards="WordPress" -n \
    docroot/wp-content/plugin
fin run phpcbf \
    --standards="WordPress" -n \
    docroot/wp-content/plugins