.php_cs.dist 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /*
  3. * This document has been generated with
  4. * https://mlocati.github.io/php-cs-fixer-configurator/#version:2.16.3|configurator
  5. * you can change this configuration by importing this file.
  6. */
  7. $header = <<<'EOF'
  8. This file is part of the Jiannei/lumen-api-starter.
  9. (c) Jiannei <longjian.huang@foxmail.com>
  10. This source file is subject to the MIT license that is bundled
  11. with this source code in the file LICENSE.
  12. EOF;
  13. $finder = PhpCsFixer\Finder::create()
  14. ->exclude('vendor')
  15. ->exclude('tests/Fixtures')
  16. ->in(__DIR__)
  17. ->append([__DIR__.'/php-cs-fixer']);
  18. $rules = [
  19. '@PSR2' => true,
  20. // PHPDoc should contain `@param` for all params.
  21. 'phpdoc_add_missing_param_annotation' => ['only_untyped'=>false],
  22. // Annotations in PHPDoc should be ordered so that `@param` annotations come first, then `@throws` annotations, then `@return` annotations.
  23. 'phpdoc_order' => false,
  24. // Annotations in PHPDoc should be grouped together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line.
  25. 'phpdoc_separation' => false,
  26. // There should not be a binary flag before strings.
  27. 'no_binary_string' => true,
  28. // Replace control structure alternative syntax to use braces.
  29. 'no_alternative_syntax' => true,
  30. // There should be no empty lines after class opening brace.
  31. 'no_blank_lines_after_class_opening' => true,
  32. // There should not be blank lines between docblock and the documented element.
  33. 'no_blank_lines_after_phpdoc' => true,
  34. // There must be a comment when fall-through is intentional in a non-empty case body.
  35. 'no_break_comment' => true,
  36. // The closing `? >` tag MUST be omitted from files containing only PHP.
  37. 'no_closing_tag' => true,
  38. // There should not be any empty comments.
  39. 'no_empty_comment' => true,
  40. // There should not be empty PHPDoc blocks.
  41. 'no_empty_phpdoc' => true,
  42. // Remove useless semicolon statements.
  43. 'no_empty_statement' => true,
  44. // Removes extra blank lines and/or blank lines following configuration.
  45. 'no_extra_blank_lines' => true,
  46. // Remove leading slashes in `use` clauses.
  47. 'no_leading_import_slash' => true,
  48. // The namespace declaration line shouldn't contain leading whitespace.
  49. 'no_leading_namespace_whitespace' => true,
  50. // Either language construct `print` or `echo` should be used.
  51. 'no_mixed_echo_print' => true,
  52. // Operator `=>` should not be surrounded by multi-line whitespaces.
  53. 'no_multiline_whitespace_around_double_arrow' => true,
  54. // Short cast `bool` using double exclamation mark should not be used.
  55. 'no_short_bool_cast' => true,
  56. // Replace short-echo `<?=` with long format `<?php echo` syntax.
  57. 'no_short_echo_tag' => true,
  58. // Single-line whitespace before closing semicolon are prohibited.
  59. 'no_singleline_whitespace_before_semicolons' => true,
  60. // When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.
  61. 'no_spaces_after_function_name' => true,
  62. // There MUST NOT be spaces around offset braces.
  63. 'no_spaces_around_offset' => true,
  64. // There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.
  65. 'no_spaces_inside_parenthesis' => true,
  66. // Replaces superfluous `elseif` with `if`.
  67. 'no_superfluous_elseif' => true,
  68. // PHP arrays should be declared using the configured syntax.ƒ
  69. 'array_syntax' => ['syntax'=>'short'],
  70. // Binary operators should be surrounded by space as configured.
  71. 'binary_operator_spaces' => true,
  72. // There MUST be one blank line after the namespace declaration.
  73. 'blank_line_after_namespace' => true,
  74. // Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.
  75. 'blank_line_after_opening_tag' => true,
  76. // An empty line feed must precede any configured statement.
  77. 'blank_line_before_statement' => true,
  78. // The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.
  79. 'braces' => true,
  80. // A single space or none should be between cast and variable.
  81. 'cast_spaces' => true,
  82. // Class, trait and interface elements must be separated with one blank line.
  83. 'class_attributes_separation' => true,
  84. // Whitespace around the keywords of a class, trait or interfaces definition should be one space.
  85. 'class_definition' => true,
  86. // Concatenation should be spaced according configuration.
  87. 'concat_space' => true,
  88. // The PHP constants `true`, `false`, and `null` MUST be written using the correct casing.
  89. 'constant_case' => true,
  90. // Equal sign in declare statement should be surrounded by spaces or not following configuration.
  91. 'declare_equal_normalize' => ['space'=>'single'],
  92. // The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words.
  93. 'elseif' => true,
  94. // PHP code MUST use only UTF-8 without BOM (remove BOM).
  95. 'encoding' => true,
  96. // Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.
  97. 'align_multiline_comment' => true,
  98. // Each element of an array must be indented exactly once.
  99. 'array_indentation' => true,
  100. // Using `isset($var) &&` multiple times should be done in one call.
  101. 'combine_consecutive_issets' => true,
  102. // Calling `unset` on multiple items should be done in one call.
  103. 'combine_consecutive_unsets' => true,
  104. // Remove extra spaces in a nullable typehint.
  105. 'compact_nullable_typehint' => true,
  106. // Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.
  107. 'escape_implicit_backslashes' => true,
  108. // Converts backtick operators to `shell_exec` calls.
  109. 'backtick_to_shell_exec' => true,
  110. // Orders the elements of classes/interfaces/traits.
  111. 'ordered_class_elements' => ['sortAlgorithm'=>'alpha'],
  112. 'header_comment' => ['header' => $header],
  113. ];
  114. $config = PhpCsFixer\Config::create()
  115. ->setRiskyAllowed(true)
  116. ->setRules($rules)
  117. ->setFinder($finder);
  118. return $config;