LoginSignup
0
0

More than 5 years have passed since last update.

PHP_Beautifier でソースコードを整形してみた

Last updated at Posted at 2018-11-14

調査

  • PHP_CodeSniffer
    • 最新の3系はPHP 5.4.0 以降に対応
    • 2系はPHP 5.1.2 以降に対応
    • PHP_CodeSniffer は、うまく動かせなかったため PHP_Beautifier を使うこととした。
  • PHP_Beautifier
    • PHP 5.0 から対応っぽい(?)

インストール

wget http://pear.php.net/get/PHP_Beautifier-0.1.15.tgz

sudo pear install PHP_Beautifier-0.1.15.tgz

使い方

php_beautifier -hでヘルプが見れる。

# スペース4個のインデント
php_beautifier input.php > output.php

# タブのインデント
php_beautifier -t input.php > output.php

php-cs-fixer を使ってみた

.php_cs
<?php
return PhpCsFixer\Config::create()
    ->setRiskyAllowed(true)
    ->setRules(array(
        '@PSR2' => true,
        'binary_operator_spaces' => array(
            'align_double_arrow' => true,
            'align_equals'       => true,
        ),
    ))
    ->setIndent("\t");
sample.phpを整形
php php-cs-fixer-v2.phar fix sample.php
0
0
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
0
0