Every language need need some sort of guidelines for developers so that they can easly understand others people code.
PHP is not different. PSR guild-lines where created to standard the coding style for better readability. Find out more about PSR here:
You can use PHP_CodeSniffer to check code against any one of these recommendations. There are also plugin available for text editors like Visual Studio Code, Sublime Text, Atom and other.
Other tools created for automatic fix where created such us:
- PHP Coding Standards Fixer
- PHP Code Beautifier and Fixer (included with PHP_CodeSniffer)
You can run phpcs manually from shell:
phpcs -sw --standard=PSR1 file.php
It will show errors and describe how to fix them. It can also be helpful to include this command in a git hook. That way, branches which contain violations against the chosen standard cannot enter the repository until those violations have been fixed.
If you have PHP_CodeSniffer, then you can fix the code layout problems reported by it, automatically, with the PHP Code Beautifier and Fixer.
phpcbf -w --standard=PSR1 file.php
Another option is to use the PHP Coding Standards Fixer. It will show which kind of errors the code structure had before it fixed them.
php-cs-fixer fix -v --rules=@PSR1 file.php
English is preferred for all symbol names and code infrastructure. Comments may be written in any language easily readable by all current and future parties who may be working on the codebase.
PHP The Right Way
Clean Code PHP.