You can nudge your life in a new direction every day.

PHP Code Sniffer commands to correct Drupal coding standards

Submitted by admin on Sun, 10/25/2020 - 17:31

PHP_CodeSniffer tokenizes PHP files and detects violations of a defined set of coding standards.

  • phpcs script detects violations of a defined coding standard
  • phpcbf script to automatically correct coding standard violations.

I could not get PHP CodeSniffer to play nice with Visual Studio code and the Drupal module extension so I ran both from the command line.

phpcs --standard=path/to/ruleset.xml --extensions=php,module path/to/file/example.module

phpcbf --standard=path/to/ruleset.xml --extensions=php,module path/to/file/example.module