LoginSignup
3
2

More than 5 years have passed since last update.

【PHP】CS-Fixerを導入する

Posted at

php cs-fixer
https://github.com/FriendsOfPHP/PHP-CS-Fixer
を用いて、PHPプロジェクトでコード整形を自動化する方法。
複数人で作業していると、無駄なコミットとかは入らないようにしたいし、可読性のことも考えるとメリット大。

composer経由で導入

composer require friendsofphp/php-cs-fixer --dev

コード整形の実行

appディレクトリ下についてコード整形を行いたい場合、以下のようなコマンドを実行。

vendor/bin/php-cs-fixer fix app 

Makefileに追加する場合

いちいち上記のコマンドを打つのも面倒なので、Makefileに make fixer として登録すると便利。

fixer:
    php vendor/bin/php-cs-fixer fix ./app && \
    php vendor/bin/php-cs-fixer fix ./database

参考ブログ

PhpStormのボタンで実行できるようにする方法など、詳しくはこちら
https://www.chatbox.blog/2018/04/23/php%E3%83%97%E3%83%AD%E3%82%B8%E3%82%A7%E3%82%AF%E3%83%88%E3%81%AB-cs-fixer%E3%82%92%E5%B0%8E%E5%85%A5%E3%81%97%E3%81%A6%E3%82%B3%E3%83%BC%E3%83%89%E6%95%B4%E5%BD%A2%E3%82%92%E8%87%AA%E5%8B%95/

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2