Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use php-cs-fixer

Shulou Source: shulou.com Published: 2022-06-02 09:44:25 10月03日 Update

This article introduces the relevant knowledge of "how to use php-cs-fixer". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

began

Recently, in the PHP Way, I saw php-cs-fixer in the code style guide chapter.

php-cs-fixer is able to automatically fix code styles for you, not just formatting.

If you only need code that is automatically formatted when saved, PhpStorm can turn this on:

Before looking at other people's projects, many of them are not formatted, at least the above PhpStorm save automatic formatting also did not open it.

Next, we'll start by turning on ways to save automatic php-cs-fixer fixes.

environment

PhpStorm

PHP 8

Install php-cs-fixer

Use global installation here

composer global require friendsofphp/php-cs-fixer

See https://cs.symfony.com/doc/installation.html

Under the root of the project, create a new file: .php-cs-fixer.php with the following content:

Tags: Code console control file format content program path style output next thing parameter manual effect article more directory knowledge project Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia MariaDB OPPO Reno Shulou Tech Info Shulou Technology