LoginSignup
29
25

More than 5 years have passed since last update.

PHP-CS-Fixerの設定が面倒くさい人のためのルールセット

Last updated at Posted at 2018-01-03

次に当てはまる場合はsuin/php-cs-fixer-rulesが便利。

  • 「PHP-CS-Fixerの設定が面倒」
  • 「詳しい人、セットアップして」
  • そして、PHP 7.1以上の環境

どんなルールが設定されているかはphp-cs-fixer-rules/Rules.phpを見ると分かる。おそらくこれと同等のものを作ろうとしたら半日はかかるので、特にこだわりがなければこれをまず使ってみるのも手だ。

ルールセットのインストール

composerでインストールできる。

composer require --dev suin/php-cs-fixer-rules

php_cs.distの設定

Suin\PhpCsFixer\Rules::create()がルールセットの配列を返してくれえるので、それをsetRulesに渡すだけ。

php_cs.dist
<?php

return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules(Suin\PhpCsFixer\Rules::create([
        // ルールセットのデフォルトを上書きしたり、ルールを追加したい場合はここに書く。
        'declare_strict_types' => false,
    ]))
    ->setFinder(PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__)
    );

以上でセットアップ完了。

29
25
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
29
25