.php-cs-fixer.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <?php
  2. $finder = PhpCsFixer\Finder::create()
  3. ->exclude('tests')
  4. ->exclude('vendor')
  5. ->in(__DIR__);
  6. return (new PhpCsFixer\Config())
  7. ->setUsingCache(false)
  8. ->setRules([
  9. '@Symfony' => true,
  10. 'combine_consecutive_unsets' => true, // 多个unset,合并成一个
  11. 'class_attributes_separation' => true,
  12. 'heredoc_to_nowdoc' => true, // 删除配置中多余的空行和/或者空行。
  13. 'no_unreachable_default_argument_value' => false, // 在函数参数中,不能有默认值在非缺省值之前的参数。有风险
  14. 'no_useless_else' => true, // 删除无用的else
  15. 'no_useless_return' => true, // 删除函数末尾无用的return
  16. 'no_empty_phpdoc' => true, // 删除空注释
  17. 'no_empty_statement' => true, // 删除多余的分号
  18. 'no_leading_namespace_whitespace' => true, // 删除namespace声明行包含前导空格
  19. 'no_spaces_inside_parenthesis' => true, // 删除括号后内两端的空格
  20. 'no_trailing_whitespace' => true, // 删除非空白行末尾的空白
  21. 'no_unused_imports' => true, // 删除未使用的use语句
  22. 'no_whitespace_before_comma_in_array' => true, // 删除数组声明中,每个逗号前的空格
  23. 'no_whitespace_in_blank_line' => true, // 删除空白行末尾的空白
  24. 'ordered_class_elements' => true,
  25. 'ordered_imports' => ['sort_algorithm' => 'alpha'],
  26. 'line_ending' => true,
  27. 'single_quote' => true,
  28. 'array_syntax' => ['syntax' => 'short'],
  29. 'array_indentation' => true, // 数组的每个元素必须缩进一次
  30. 'ternary_operator_spaces' => true, // 标准化三元运算的格式
  31. 'whitespace_after_comma_in_array' => true, // 在数组声明中,每个逗号后必须有一个空格
  32. 'unary_operator_spaces' => true,
  33. 'binary_operator_spaces' => true,
  34. 'blank_line_before_statement' => [
  35. 'statements' => ['break', 'continue', 'declare', 'return', 'throw', 'try'],
  36. ],
  37. 'phpdoc_single_line_var_spacing' => true,
  38. ])
  39. ->setFinder($finder);