plugin-php
Intro
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 this be used in production?
We're considering the plugin to be stable when pure PHP files are formatted. Formatting of files that contain mixed PHP and HTML is still considered unstable - please see open issues with the tag "inline" for details.
If you want to use the plugin in production, we recommend limiting its scope to pure PHP files.
Input
array_map(function($arg1,$arg2) use ( $var1, $var2 ) {
return $arg1+$arg2/($var+$var2);
}, array("complex"=>"code","with"=>"inconsistent","formatting"=>"is", "hard" => "to", "maintain"=>true));
Output
array_map(
function ($arg1, $arg2) use ($var1, $var2) {
return $arg1 + $arg2 / ($var + $var2);
},
array(
"complex" => "code",
"with" => "inconsistent",
"formatting" => "is",
"hard" => "to",
"maintain" => true
)
);
Playground
You can give the plugin a try in our playground!
Install
yarn:
yarn add --dev prettier @prettier/plugin-php
# or globally
yarn global add prettier @prettier/plugin-php
npm:
npm install --save-dev prettier @prettier/plugin-php
# or globally
npm install --global prettier @prettier/plugin-php