PHP-CS-Fixer Beautifier
About
PHP-CS-Fixer beautifier for Unibeautify
Package | Docs | Latest |
---|---|---|
@unibeautify/beautifier-php-cs-fixer | v0.4.0 | |
unibeautify | v0.17.1 |
Prerequisites
Please install the following prerequisites.
PHP-CS-Fixer executable
PHP-CS-Fixer executable should not be confused with PHP-CS-Fixer beautifier with the same name. Executables are non-Node.js tools for code formatting while beautifiers are Node.js packages which wrap an executable to be used by Unibeautify.
PHP-CS-Fixer executable is a third-party program you must install manually and is required for beautification.
See https://cs.sensiolabs.org/ for more information.
Install PHP-CS-Fixer (php-cs-fixer
) by following https://cs.sensiolabs.org/#installation.
If you have questions or want to report a bug, go to https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues.
Install
Install with npm
:
npm install --save-dev unibeautify @unibeautify/beautifier-php-cs-fixer
Or with yarn
:
yarn add --dev unibeautify @unibeautify/beautifier-php-cs-fixer
Usage
Add PHP-CS-Fixer
to beautifiers
language option.
A .unibeautifyrc.json
file would look like the following:
{
"PHP": {
"beautifiers": [
"PHP-CS-Fixer"
]
}
}
Advanced
The following beautifier option(s) are supported:
prefer_beautifier_config
See beautifier options docs for more information.
Example advanced configuration:
{
"PHP": {
"beautifiers": [
"PHP-CS-Fixer"
],
"PHP-CS-Fixer": {
"prefer_beautifier_config": true,
"PHP-CS-Fixer": {
"path": "/absolute/path/to/php-cs-fixer"
}
}
}
}
Options
No configuration options are supported. The following languages are supported without options: PHP.
FAQ
How to use PHP-CS-Fixer in Atom, VSCode, and other editors?
See the editor integration documentation for installation instructions for your editor of choice.
How to use PHP-CS-Fixer configuration file?
You can override Unibeautify configuration and use PHP-CS-Fixer's own configuration file instead with prefer_beautifier_config
beautifier option.
{
"LANGUAGE_NAME": {
"beautifiers": [
"PHP-CS-Fixer"
],
"PHP-CS-Fixer": {
"prefer_beautifier_config": "path/to/PHP-CS-Fixer/config/file"
}
}
}
See beautifier options docs for more information.
How to enable PHP-CS-Fixer to format on save?
See the editor integration documentation for format on save instructions for your editor of choice.
How to run PHP-CS-Fixer on all files?
You can run PHP-CS-Fixer on all of your files for every commit with Unibeautify CI.
Is there a PHP-CS-Fixer sandbox or playground?
You can quickly try PHP-CS-Fixer online with Unibeautify Playground.
Troubleshooting
Below are instructions for each of the supported Operating Systems.
Windows
Open the Command Prompt.
Show me how to open the Command Prompt.
Find the path to PHP-CS-Fixer by running the command:
where php-cs-fixer
Which will return an absolute path like one of the following:
C:\absolute\path\to\php-cs-fixer
C:\absolute\path\to\php-cs-fixer.exe
C:\absolute\path\to\php-cs-fixer.bat
If where
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/php-cs-fixer
with your specific executable path value.
macOS
Open the Terminal application.
Show me how to open the Terminal.
Find the path to PHP-CS-Fixer by running the command:
which php-cs-fixer
Which will return an absolute path like one of the following:
/absolute/path/to/php-cs-fixer
/absolute/path/to/php-cs-fixer.sh
/absolute/path/to/php-cs-fixer.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable:
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section and replace /absolute/path/to/php-cs-fixer
with your specific executable path value.
Linux
Open the Terminal application.
Show me how to open the Terminal.
Find the path to PHP-CS-Fixer by running the command:
which php-cs-fixer
Which will return an absolute path like one of the following:
/absolute/path/to/php-cs-fixer
/absolute/path/to/php-cs-fixer.sh
/absolute/path/to/php-cs-fixer.bash
If which
fails to return an executable path then you need to fix your PATH
Environment Variable.
Show me how to change my
PATH
environment variable.
If you know the executable path go to the Configure section replace /absolute/path/to/php-cs-fixer
with your specific executable path value.