.php_cs.dist 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. <?php
  2. $finder = PhpCsFixer\Finder::create()
  3. ->exclude('vendor')
  4. ->in('samples')
  5. ->in('src')
  6. ->in('tests');
  7. return PhpCsFixer\Config::create()
  8. ->setRiskyAllowed(true)
  9. ->setFinder($finder)
  10. ->setRules([
  11. 'align_multiline_comment' => true,
  12. 'array_syntax' => ['syntax' => 'short'],
  13. 'backtick_to_shell_exec' => true,
  14. 'binary_operator_spaces' => true,
  15. 'blank_line_after_namespace' => true,
  16. 'blank_line_after_opening_tag' => true,
  17. 'blank_line_before_statement' => true,
  18. 'braces' => true,
  19. 'cast_spaces' => true,
  20. 'class_attributes_separation' => ['elements' => ['method', 'property']], // const are often grouped with other related const
  21. 'class_definition' => true,
  22. 'class_keyword_remove' => false, // ::class keyword gives us beter support in IDE
  23. 'combine_consecutive_issets' => true,
  24. 'combine_consecutive_unsets' => true,
  25. 'compact_nullable_typehint' => true,
  26. 'concat_space' => ['spacing' => 'one'],
  27. 'declare_equal_normalize' => true,
  28. 'declare_strict_types' => false, // Too early to adopt strict types
  29. 'dir_constant' => true,
  30. 'doctrine_annotation_array_assignment' => true,
  31. 'doctrine_annotation_braces' => true,
  32. 'doctrine_annotation_indentation' => true,
  33. 'doctrine_annotation_spaces' => true,
  34. 'elseif' => true,
  35. 'encoding' => true,
  36. 'ereg_to_preg' => true,
  37. 'escape_implicit_backslashes' => true,
  38. 'explicit_indirect_variable' => false, // I feel it makes the code actually harder to read
  39. 'explicit_string_variable' => false, // I feel it makes the code actually harder to read
  40. 'final_internal_class' => true,
  41. 'full_opening_tag' => true,
  42. 'function_declaration' => true,
  43. 'function_to_constant' => true,
  44. 'function_typehint_space' => true,
  45. 'general_phpdoc_annotation_remove' => false, // No use for that
  46. 'hash_to_slash_comment' => true,
  47. 'header_comment' => false, // We don't use common header in all our files
  48. 'heredoc_to_nowdoc' => false, // Not sure about this one
  49. 'include' => true,
  50. 'increment_style' => true,
  51. 'indentation_type' => true,
  52. 'is_null' => ['use_yoda_style' => false],
  53. 'linebreak_after_opening_tag' => true,
  54. 'line_ending' => true,
  55. 'list_syntax' => ['syntax' => 'long'], // Stay compatiblew with PHP 5.6
  56. 'lowercase_cast' => true,
  57. 'lowercase_constants' => true,
  58. 'lowercase_keywords' => true,
  59. 'magic_constant_casing' => true,
  60. 'mb_str_functions' => false, // No, too dangerous to change that
  61. 'method_argument_space' => true,
  62. 'method_chaining_indentation' => true,
  63. 'method_separation' => true,
  64. 'modernize_types_casting' => true,
  65. 'multiline_comment_opening_closing' => true,
  66. 'native_function_casing' => true,
  67. 'native_function_invocation' => false, // This is risky and seems to be micro-optimization that make code uglier so not worth it, at least for now
  68. 'new_with_braces' => true,
  69. 'no_alias_functions' => true,
  70. 'no_blank_lines_after_class_opening' => true,
  71. 'no_blank_lines_after_phpdoc' => true,
  72. 'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace
  73. 'no_break_comment' => true,
  74. 'no_closing_tag' => true,
  75. 'no_empty_comment' => true,
  76. 'no_empty_phpdoc' => true,
  77. 'no_empty_statement' => true,
  78. 'no_extra_blank_lines' => true,
  79. 'no_homoglyph_names' => true,
  80. 'no_leading_import_slash' => true,
  81. 'no_leading_namespace_whitespace' => true,
  82. 'no_mixed_echo_print' => true,
  83. 'no_multiline_whitespace_around_double_arrow' => true,
  84. 'no_multiline_whitespace_before_semicolons' => true,
  85. 'non_printable_character' => true,
  86. 'no_null_property_initialization' => true,
  87. 'no_php4_constructor' => true,
  88. 'normalize_index_brace' => true,
  89. 'no_short_bool_cast' => true,
  90. 'no_short_echo_tag' => true,
  91. 'no_singleline_whitespace_before_semicolons' => true,
  92. 'no_spaces_after_function_name' => true,
  93. 'no_spaces_around_offset' => true,
  94. 'no_spaces_inside_parenthesis' => true,
  95. 'no_superfluous_elseif' => false, // Might be risky on a huge code base
  96. 'not_operator_with_space' => false, // No we prefer to keep '!' without spaces
  97. 'not_operator_with_successor_space' => false, // idem
  98. 'no_trailing_comma_in_list_call' => true,
  99. 'no_trailing_comma_in_singleline_array' => true,
  100. 'no_trailing_whitespace_in_comment' => true,
  101. 'no_trailing_whitespace' => true,
  102. 'no_unneeded_control_parentheses' => true,
  103. 'no_unneeded_curly_braces' => true,
  104. 'no_unneeded_final_method' => true,
  105. 'no_unreachable_default_argument_value' => true,
  106. 'no_unused_imports' => true,
  107. 'no_useless_else' => true,
  108. 'no_useless_return' => true,
  109. 'no_whitespace_before_comma_in_array' => true,
  110. 'no_whitespace_in_blank_line' => true,
  111. 'object_operator_without_whitespace' => true,
  112. 'ordered_class_elements' => false, // We prefer to keep some freedom
  113. 'ordered_imports' => true,
  114. 'phpdoc_add_missing_param_annotation' => true,
  115. 'phpdoc_align' => false, // Waste of time
  116. 'phpdoc_annotation_without_dot' => true,
  117. 'phpdoc_indent' => true,
  118. 'phpdoc_inline_tag' => true,
  119. 'phpdoc_no_access' => true,
  120. 'phpdoc_no_alias_tag' => true,
  121. 'phpdoc_no_empty_return' => true,
  122. 'phpdoc_no_package' => true,
  123. 'phpdoc_no_useless_inheritdoc' => true,
  124. 'phpdoc_order' => true,
  125. 'phpdoc_return_self_reference' => true,
  126. 'phpdoc_scalar' => true,
  127. 'phpdoc_separation' => true,
  128. 'phpdoc_single_line_var_spacing' => true,
  129. 'phpdoc_summary' => true,
  130. 'phpdoc_to_comment' => true,
  131. 'phpdoc_trim' => true,
  132. 'phpdoc_types_order' => true,
  133. 'phpdoc_types' => true,
  134. 'phpdoc_var_without_name' => true,
  135. 'php_unit_construct' => true,
  136. 'php_unit_dedicate_assert' => true,
  137. 'php_unit_expectation' => true,
  138. 'php_unit_fqcn_annotation' => true,
  139. 'php_unit_mock' => true,
  140. 'php_unit_namespaced' => true,
  141. 'php_unit_no_expectation_annotation' => true,
  142. 'php_unit_strict' => false, // We sometime actually need assertEquals
  143. 'php_unit_test_annotation' => true,
  144. 'php_unit_test_class_requires_covers' => false, // We don't care as much as we should about coverage
  145. 'pow_to_exponentiation' => false,
  146. 'protected_to_private' => true,
  147. 'psr0' => true,
  148. 'psr4' => true,
  149. 'random_api_migration' => false, // This breaks our unit tests
  150. 'return_type_declaration' => true,
  151. 'self_accessor' => true,
  152. 'semicolon_after_instruction' => false, // Buggy in `samples/index.php`
  153. 'short_scalar_cast' => true,
  154. 'silenced_deprecation_error' => true,
  155. 'simplified_null_return' => false, // While technically correct we prefer to be explicit when returning null
  156. 'single_blank_line_at_eof' => true,
  157. 'single_blank_line_before_namespace' => true,
  158. 'single_class_element_per_statement' => true,
  159. 'single_import_per_statement' => true,
  160. 'single_line_after_imports' => true,
  161. 'single_line_comment_style' => true,
  162. 'single_quote' => true,
  163. 'space_after_semicolon' => true,
  164. 'standardize_not_equals' => true,
  165. 'static_lambda' => false, // Risky if we can't guarantee nobody use `bindTo()`
  166. 'strict_comparison' => false, // No, too dangerous to change that
  167. 'strict_param' => false, // No, too dangerous to change that
  168. 'switch_case_semicolon_to_colon' => true,
  169. 'switch_case_space' => true,
  170. 'ternary_operator_spaces' => true,
  171. 'ternary_to_null_coalescing' => false, // Cannot use that with PHP 5.6
  172. 'trailing_comma_in_multiline_array' => true,
  173. 'trim_array_spaces' => true,
  174. 'unary_operator_spaces' => true,
  175. 'visibility_required' => true,
  176. 'void_return' => false, // Cannot use that with PHP 5.6
  177. 'whitespace_after_comma_in_array' => true,
  178. 'yoda_style' => false,
  179. ]);