Skip to content

Configuring PHP Codesniffer

jlleblanc edited this page · 1 revision

PHP Codesniffer can be used to automatically check your code for style issues. This can be done through a Git pre-commit hook. The hook will prevent you from committing code that does not conform to the Joomla Platform coding standards.

To add this hook, first install PHP Codesniffer. Once PHP Codesniffer is installed, you will need to know where the phpcs binary is located. This can typically be found by entering which phpcs on the command line.

Finally, you will need to add the hook itself. This project has a PHP Codesniffer Git hook ready to configure. Once you've copied the config and pre-commit files into the .git/hooks folder, make sure that pre-commit is executable. Then edit the config file, supplying values for these variables:

  • PHPCS_BIN - use the full path to your phpcs binary
  • PHPCS_CODING_STANDARD - set this to build/phpcs/Joomla

Now, whenever you commit code, it will be checked against the Joomla Platform coding standards. If there are any issues in files you have changed, it will stop the commit and display a report.

Something went wrong with that request. Please try again.