Code Formatter¶
A code formatter is an automated tool that apply coding conventions to the source code.
It may, for example, move the opening bracket of a block on the name of the signature or below; it may add a space between a cast operator and its expression; etc.
Code formatters modifies the presentation of the code, and do not change the underlying execution of it: although, some of the coding conventions may cross that line. For example, rewriting != clauses to == in ifthen usually leads to voluminous modifications.
Some code formatters only report specifications violations. Others apply corrections automatically.
Popular coding conventions are PSR-12, or per framework, such as Symfony Coding Standard, CakePHP, CodeIgniter, Wordpress, etc.
<?php
// two distinct coding conventions.
function foo() { return 1; }
function goo()
{
return 2;
}
?>
See also A curated list of code formatters and PHP-Styler: A Back-To-Formula Rewrite.
Related : PHP Standards Recommendations (PSR)
Related packages : lkrms/pretty-php, friendsofphp/php-cs-fixer, squizlabs/php_codesniffer