php-cs-fixer.dist.php 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. $finder = PhpCsFixer\Finder::create()
  3. ->ignoreDotFiles(false)
  4. ->ignoreVCSIgnored(true)
  5. ->exclude(['dev-tools/phpstan', 'tests/Fixtures'])
  6. ->in([
  7. __DIR__.'/app',
  8. __DIR__.'/config',
  9. __DIR__.'/routes',
  10. ])
  11. ;
  12. $config = new PhpCsFixer\Config();
  13. $config
  14. ->setRiskyAllowed(true)
  15. ->setRules([
  16. '@Symfony' => true,
  17. '@PSR1' => true,
  18. '@PSR2' => true,
  19. '@PSR12' => true,
  20. 'blank_line_after_namespace' => true, // namespace 之后空一行
  21. 'increment_style' => false, // 阻止 $a++ 变成 ++$a
  22. 'array_syntax' => ['syntax' => 'short'], // 使用 [] 来定义数组
  23. 'no_useless_else' => true, // 删除没有使用的 else 节点
  24. 'no_useless_return' => true, // 删除没有使用的 return 语句
  25. 'self_accessor' => false, // 在当前类中使用 self 代替类名
  26. 'php_unit_construct' => true, // 单元测试使用 assertTrue 来代替 assertSame(true, $foo)
  27. 'single_quote' => true, // 简单字符串应该使用单引号代替双引号
  28. 'no_unused_imports' => true, // 删除没用到的 use
  29. 'no_singleline_whitespace_before_semicolons' => true, // 禁止只有单行空格和分号的写法
  30. 'no_empty_statement' => true, // 删除多余的分号
  31. 'no_whitespace_in_blank_line' => true, // 删除空行中的空格
  32. 'standardize_not_equals' => false, // 使用 <> 代替 !=
  33. 'combine_consecutive_unsets' => true, // 当多个 unset 使用的时候,合并处理
  34. 'concat_space' => ['spacing' => 'one'], // .拼接必须有空格分割
  35. 'array_indentation' => true, // 数组的每个元素必须缩进一次
  36. 'blank_line_before_statement' => [ // 空行换行必须在任何已配置的语句之前
  37. 'statements' => [
  38. 'include',
  39. 'include_once',
  40. 'require',
  41. 'require_once',
  42. 'declare',
  43. 'exit',
  44. 'return',
  45. 'goto',
  46. 'throw',
  47. 'try',
  48. 'yield'
  49. ]
  50. ],
  51. 'binary_operator_spaces' => ['default' => 'align_single_space_minimal'], // 等号对齐、数字箭头符号对齐
  52. 'align_multiline_comment' => ['comment_type' => 'phpdocs_only'], // 注释按标准文档格式
  53. 'no_blank_lines_after_class_opening' => true, // 类的第一行,不能空行
  54. 'phpdoc_separation' => true, // 不同注释部分按照单空行隔开
  55. 'phpdoc_single_line_var_spacing' => true, // 单行 @var 注释空格隔开
  56. 'phpdoc_indent' => true, // 文档注释与代码有相同的间隔符
  57. 'phpdoc_align' => [ // 文档对齐方式
  58. 'align' => 'vertical',
  59. 'tags' => [
  60. 'param', 'throws', 'type', 'var', 'property'
  61. ]
  62. ]
  63. ])
  64. ->setFinder($finder)
  65. ;
  66. return $config;