Allows in the Emacs editor to fix most issues in PHP code when you want to follow the coding standards PSR-1 and PSR-2.
Under the hood, this package provides the customisable Elisp command php-cs-fix wich wraps the command line php-cs-fixer version >=2.0 provided by the powerful PHP Coding Standards Fixer
Install PHP-CS-Fixer so that the command line php-cs-fixer is
executable in your system.
This package can be installed from Melpa : M-x package-install <RET> php-cs-fixer <RET>
This package requires that the cl-lib package was installed.
To install php-cs-fixer.el, place php-cs-fixer.el in a
directory of your choice, add it to your load path and require
php-cs-fixer writing this code in your emacs configuration file (aka .emacs) :
(add-to-list 'load-path "/place/where/you/put/it/")
(require 'php-cs-fixer)Either evaluate both statements with C-x C-e, or restart Emacs.
Try M-x php-cs-fix [ret] when editing a PHP file.
If you want an automatic fix when saving all php files, place this code in your Emacs configuration file :
(add-hook 'before-save-hook 'php-cs-fixer-before-save)php-cs-fixer-commandis thephp-cs-fixercommand (default isphp-cs-fixer) ;php-cs-fixer-config-optionis thephp-cs-fixer --configoption value (default isnil, see the filephp-cs-fixer-config.phpfor an example of configuration file) ;php-cs-fixer-rules-level-part-optionsis thephp-cs-fixer --rulesbase part options value (default is'("@Symfony")) ;php-cs-fixer-rules-fixer-part-optionsis thephp-cs-fixer --rulesexact rules part options value (default is("no_multiline_whitespace_before_semicolons" "concat_space")).php-cs-fixer-fix-popup-on-error: should fixing a file popups an error buffer when it failed ?
Warning : whennil(the default), error fixing a file will calls the Emacs functionwarnthat can be inhibited bywarning-suppress-types.
Try M-x customize-group [ret] php-cs-fixer [ret] to modify the values of these variables.