Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Command line formatter for PHP and Javascript

Are there any command line (not interactive, not web-based) tools that will reformat (pretty-print) PHP and Javascript code?

like image 672
rwallace Avatar asked Aug 08 '09 16:08

rwallace


People also ask

Does prettier work with PHP?

Prettier is an opinionated code formatter. It enforces a consistent style by parsing your code and re-printing it with its own rules that take the maximum line length into account, wrapping code when necessary. This plugin adds support for the PHP language to Prettier.

Can PHP be used for command line scripts?

As of version 4.3. 0, PHP supports a new SAPI type (Server Application Programming Interface) named CLI which means Command Line Interface. As the name implies, this SAPI type main focus is on developing shell (or desktop as well) applications with PHP.

How do I arrange PHP code in Visual Studio?

Add the extension Format HTML in PHP to Visual Studio Code. Or search in extensions with "format HTML in PHP". After reload, use Shift + Alt + F .


1 Answers

PHP_ Beautifier is very outdated! For a more modern approach try php-cs-fixer

Example command: php-cs-fixer fix --rules=@PSR2 path/to/php/src

A second alternative is PHP_CodeSniffer

Example command: phpcbf --standard=PSR2 path/to/php/src

like image 52
Moak Avatar answered Sep 20 '22 23:09

Moak