phpfmt/fmt

此包已被废弃,不再维护。未建议替代包。

K&R 和 phpfmt 编码标准

维护者

详细信息

github.com/phpfmt/fmt

源代码

问题

安装数: 1,379

依赖者: 0

建议者: 0

安全: 0

星标: 630

关注者: 34

分支: 44

类型:应用

dev-master 2016-06-01 02:11 UTC

This package is not auto-updated.

Last update: 2016-06-01 02:11:30 UTC


README

本项目遵循行为准则。

报告问题。

构建状态

  • 主分支: 构建状态

要求

  • 运行格式化器需要 PHP >= 7.0.0。注意,如果需要,格式化器可以解析和格式化 PHP 文件版本 4。HHVM 不受支持。

编辑器插件

使用方法

$ php fmt.phar filename.php

$ php fmt.phar --help
Usage: fmt.phar [-hv] [-o=FILENAME] [--config=FILENAME] [--cache[=FILENAME]] [options] <target>
  --cache[=FILENAME]                cache file. Default: .php.tools.cache
  --config=FILENAME                 configuration file. Default: .phpfmt.ini
  --dry-run                         Runs the formatter without atually changing files;
                                    returns exit code 1 if changes would have been applied
  --ignore=PATTERN-1,PATTERN-N,...  ignore file names whose names contain any PATTERN-N
  --lint-before                     lint files before pretty printing (PHP must be declared in %PATH%/$PATH)
  --no-backup                       no backup file (original.php~)
  --profile=NAME                    use one of profiles present in configuration file
  --version                         version
  -h, --help                        this help message
  -o=-                              output the formatted code to standard output
  -o=file                           output the formatted code to "file"
  -v                                verbose

If <target> is "-", it reads from stdin

代码格式化器做什么?

K&R 配置

之前 之后
<?php
for($i = 0; $i < 10; $i++)
{
if($i%2==0)
echo "Flipflop";
}
<?php
for ($i = 0; $i < 10; $i++) {
    if ($i%2 == 0) {
        echo "Flipflop";
    }
}
<?php
$a = 10;
$otherVar = 20;
$third = 30;
<?php
$a        = 10;
$otherVar = 20;
$third    = 30;
<?php
namespace NS\Something;
use \OtherNS\C;
use \OtherNS\B;
use \OtherNS\A;
use \OtherNS\D;

$a = new A();
$b = new C();
$d = new D();
<?php
namespace NS\Something;

use \OtherNS\A;
use \OtherNS\C;
use \OtherNS\D;

$a = new A();
$b = new C();
$d = new D();
注意它如何排序 use 子句,并移除未使用的子句