1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- <?php
- $finder = PhpCsFixer\Finder::create()
- ->ignoreDotFiles(false)
- ->ignoreVCSIgnored(true)
- ->exclude(['dev-tools/phpstan', 'tests/Fixtures'])
- ->in([
- __DIR__.'/app',
- __DIR__.'/config',
- __DIR__.'/routes',
- ])
- ;
- $config = new PhpCsFixer\Config();
- $config
- ->setRiskyAllowed(true)
- ->setRules([
- '@Symfony' => true,
- '@PSR1' => true,
- '@PSR2' => true,
- '@PSR12' => true,
- 'blank_line_after_namespace' => true, // namespace 之后空一行
- 'increment_style' => false, // 阻止 $a++ 变成 ++$a
- 'array_syntax' => ['syntax' => 'short'], // 使用 [] 来定义数组
- 'no_useless_else' => true, // 删除没有使用的 else 节点
- 'no_useless_return' => true, // 删除没有使用的 return 语句
- 'self_accessor' => false, // 在当前类中使用 self 代替类名
- 'php_unit_construct' => true, // 单元测试使用 assertTrue 来代替 assertSame(true, $foo)
- 'single_quote' => true, // 简单字符串应该使用单引号代替双引号
- 'no_unused_imports' => true, // 删除没用到的 use
- 'no_singleline_whitespace_before_semicolons' => true, // 禁止只有单行空格和分号的写法
- 'no_empty_statement' => true, // 删除多余的分号
- 'no_whitespace_in_blank_line' => true, // 删除空行中的空格
- 'standardize_not_equals' => false, // 使用 <> 代替 !=
- 'combine_consecutive_unsets' => true, // 当多个 unset 使用的时候,合并处理
- 'concat_space' => ['spacing' => 'one'], // .拼接必须有空格分割
- 'array_indentation' => true, // 数组的每个元素必须缩进一次
- 'blank_line_before_statement' => [ // 空行换行必须在任何已配置的语句之前
- 'statements' => [
- 'include',
- 'include_once',
- 'require',
- 'require_once',
- 'declare',
- 'exit',
- 'return',
- 'goto',
- 'throw',
- 'try',
- 'yield'
- ]
- ],
- 'binary_operator_spaces' => ['default' => 'align_single_space_minimal'], // 等号对齐、数字箭头符号对齐
- 'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], // 注释按标准文档格式
- 'no_blank_lines_after_class_opening' => true, // 类的第一行,不能空行
- 'phpdoc_separation' => true, // 不同注释部分按照单空行隔开
- 'phpdoc_single_line_var_spacing' => true, // 单行 @var 注释空格隔开
- 'phpdoc_indent' => true, // 文档注释与代码有相同的间隔符
- 'phpdoc_align' => [ // 文档对齐方式
- 'align' => 'vertical',
- 'tags' => [
- 'param', 'throws', 'type', 'var', 'property'
- ]
- ]
- ])
- ->setFinder($finder)
- ;
- return $config;
|