php-mode supports several different coding styles out of the box:
Each coding style has its own settings for indentation. For example, the
drupal style uses 2 spaces for indentation, whereas
wordpress uses tabs.
dir-locals.el, Emacs can automatically set a coding style on a
per-project basis. This is /extremely/ helpful when working on different
projects that need to be formatted in a particular way.
Here’s an example of a
dir-locals.el file that will enable the
coding style for PHP files:
((php-mode . ((php-project-coding-style . wordpress))))
The coding style value doesn’t need to be quoted (otherwise you might see a
(wrong-type-argument symbolp wordpress)) error on startup.
If flycheck and phpcs are installed, they can be configured to highlight coding style infractions:
((php-mode . ((php-project-coding-style . wordpress) (flycheck-phpcs-standard . "WordPress-VIP") (flycheck-checkers . (php-phpcs)))))
The above code will setup
php-mode to use tabs, and will also highlight any
code that doesn’t meet WordPress VIP standards.