.php-cs-fixer.dist.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. <?php
  2. $finder = PhpCsFixer\Finder::create()
  3. ->exclude('vendor')
  4. ->notPath('src/PhpSpreadsheet/Writer/ZipStream3.php')
  5. ->in(__DIR__);
  6. $config = new PhpCsFixer\Config();
  7. $config
  8. ->setRiskyAllowed(true)
  9. ->setFinder($finder)
  10. ->setCacheFile(sys_get_temp_dir() . '/php-cs-fixer' . preg_replace('~\W~', '-', __DIR__))
  11. ->setRules([
  12. 'align_multiline_comment' => true,
  13. 'array_indentation' => true,
  14. 'array_syntax' => ['syntax' => 'short'],
  15. 'backtick_to_shell_exec' => true,
  16. 'binary_operator_spaces' => true,
  17. 'blank_line_after_namespace' => true,
  18. 'blank_line_after_opening_tag' => true,
  19. 'blank_line_before_statement' => true,
  20. 'braces' => true,
  21. 'cast_spaces' => true,
  22. 'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']], // const are often grouped with other related const
  23. 'class_definition' => false,
  24. 'class_keyword_remove' => false, // ::class keyword gives us better support in IDE
  25. 'combine_consecutive_issets' => true,
  26. 'combine_consecutive_unsets' => true,
  27. 'combine_nested_dirname' => true,
  28. 'comment_to_phpdoc' => false, // interferes with annotations
  29. 'compact_nullable_typehint' => true,
  30. 'concat_space' => ['spacing' => 'one'],
  31. 'constant_case' => true,
  32. 'date_time_immutable' => false, // Break our unit tests
  33. 'declare_equal_normalize' => true,
  34. 'declare_strict_types' => false, // Too early to adopt strict types
  35. 'dir_constant' => true,
  36. 'doctrine_annotation_array_assignment' => true,
  37. 'doctrine_annotation_braces' => true,
  38. 'doctrine_annotation_indentation' => true,
  39. 'doctrine_annotation_spaces' => true,
  40. 'elseif' => true,
  41. 'encoding' => true,
  42. 'ereg_to_preg' => true,
  43. 'escape_implicit_backslashes' => true,
  44. 'explicit_indirect_variable' => false, // I feel it makes the code actually harder to read
  45. 'explicit_string_variable' => false, // I feel it makes the code actually harder to read
  46. 'final_class' => false, // We need non-final classes
  47. 'final_internal_class' => true,
  48. 'final_public_method_for_abstract_class' => false, // We need non-final methods
  49. 'self_static_accessor' => true,
  50. 'fopen_flag_order' => true,
  51. 'fopen_flags' => true,
  52. 'full_opening_tag' => true,
  53. 'fully_qualified_strict_types' => true,
  54. 'function_declaration' => true,
  55. 'function_to_constant' => true,
  56. 'function_typehint_space' => true,
  57. 'general_phpdoc_annotation_remove' => ['annotations' => ['access', 'category', 'copyright']],
  58. 'global_namespace_import' => true,
  59. 'header_comment' => false, // We don't use common header in all our files
  60. 'heredoc_indentation' => true,
  61. 'heredoc_to_nowdoc' => false, // Not sure about this one
  62. 'implode_call' => true,
  63. 'include' => true,
  64. 'increment_style' => true,
  65. 'indentation_type' => true,
  66. 'is_null' => true,
  67. 'line_ending' => true,
  68. 'linebreak_after_opening_tag' => true,
  69. 'list_syntax' => ['syntax' => 'short'],
  70. 'logical_operators' => true,
  71. 'lowercase_cast' => true,
  72. 'lowercase_keywords' => true,
  73. 'lowercase_static_reference' => true,
  74. 'magic_constant_casing' => true,
  75. 'magic_method_casing' => true,
  76. 'mb_str_functions' => false, // No, too dangerous to change that
  77. 'method_argument_space' => true,
  78. 'method_chaining_indentation' => true,
  79. 'modernize_types_casting' => true,
  80. 'multiline_comment_opening_closing' => true,
  81. 'multiline_whitespace_before_semicolons' => true,
  82. 'native_constant_invocation' => false, // Micro optimization that look messy
  83. 'native_function_casing' => true,
  84. 'native_function_invocation' => false, // I suppose this would be best, but I am still unconvinced about the visual aspect of it
  85. 'native_function_type_declaration_casing' => true,
  86. 'new_with_braces' => true,
  87. 'no_alias_functions' => true,
  88. 'no_alternative_syntax' => true,
  89. 'no_binary_string' => true,
  90. 'no_blank_lines_after_class_opening' => true,
  91. 'no_blank_lines_after_phpdoc' => true,
  92. 'no_blank_lines_before_namespace' => false, // we want 1 blank line before namespace
  93. 'no_break_comment' => true,
  94. 'no_closing_tag' => true,
  95. 'no_empty_comment' => true,
  96. 'no_empty_phpdoc' => true,
  97. 'no_empty_statement' => true,
  98. 'no_extra_blank_lines' => true,
  99. 'no_homoglyph_names' => true,
  100. 'no_leading_import_slash' => true,
  101. 'no_leading_namespace_whitespace' => true,
  102. 'no_mixed_echo_print' => true,
  103. 'no_multiline_whitespace_around_double_arrow' => true,
  104. 'no_null_property_initialization' => true,
  105. 'no_php4_constructor' => true,
  106. 'no_short_bool_cast' => true,
  107. 'echo_tag_syntax' => ['format' => 'long'],
  108. 'no_singleline_whitespace_before_semicolons' => true,
  109. 'no_spaces_after_function_name' => true,
  110. 'no_spaces_around_offset' => true,
  111. 'no_spaces_inside_parenthesis' => true,
  112. 'no_superfluous_elseif' => false, // Might be risky on a huge code base
  113. 'no_superfluous_phpdoc_tags' => ['allow_mixed' => true],
  114. 'no_trailing_comma_in_list_call' => true,
  115. 'no_trailing_comma_in_singleline_array' => true,
  116. 'no_trailing_whitespace' => true,
  117. 'no_trailing_whitespace_in_comment' => true,
  118. 'no_unneeded_control_parentheses' => true,
  119. 'no_unneeded_curly_braces' => true,
  120. 'no_unneeded_final_method' => true,
  121. 'no_unreachable_default_argument_value' => true,
  122. 'no_unset_cast' => true,
  123. 'no_unset_on_property' => true,
  124. 'no_unused_imports' => true,
  125. 'no_useless_else' => true,
  126. 'no_useless_return' => true,
  127. 'no_whitespace_before_comma_in_array' => true,
  128. 'no_whitespace_in_blank_line' => true,
  129. 'non_printable_character' => true,
  130. 'normalize_index_brace' => true,
  131. 'not_operator_with_space' => false, // No we prefer to keep '!' without spaces
  132. 'not_operator_with_successor_space' => false, // idem
  133. 'nullable_type_declaration_for_default_null_value' => true,
  134. 'object_operator_without_whitespace' => true,
  135. 'ordered_class_elements' => false, // We prefer to keep some freedom
  136. 'ordered_imports' => true,
  137. 'ordered_interfaces' => true,
  138. 'php_unit_construct' => true,
  139. 'php_unit_dedicate_assert' => true,
  140. 'php_unit_dedicate_assert_internal_type' => true,
  141. 'php_unit_expectation' => true,
  142. 'php_unit_fqcn_annotation' => true,
  143. 'php_unit_internal_class' => false, // Because tests are excluded from package
  144. 'php_unit_method_casing' => true,
  145. 'php_unit_mock' => true,
  146. 'php_unit_mock_short_will_return' => true,
  147. 'php_unit_namespaced' => true,
  148. 'php_unit_no_expectation_annotation' => true,
  149. 'phpdoc_order_by_value' => ['annotations' => ['covers']],
  150. 'php_unit_set_up_tear_down_visibility' => true,
  151. 'php_unit_size_class' => false, // That seems extra work to maintain for little benefits
  152. 'php_unit_strict' => false, // We sometime actually need assertEquals
  153. 'php_unit_test_annotation' => true,
  154. 'php_unit_test_case_static_method_calls' => ['call_type' => 'self'],
  155. 'php_unit_test_class_requires_covers' => false, // We don't care as much as we should about coverage
  156. 'phpdoc_add_missing_param_annotation' => false, // Don't add things that bring no value
  157. 'phpdoc_align' => false, // Waste of time
  158. 'phpdoc_annotation_without_dot' => true,
  159. 'phpdoc_indent' => true,
  160. //'phpdoc_inline_tag' => true,
  161. 'phpdoc_line_span' => false, // Unfortunately our old comments turn even uglier with this
  162. 'phpdoc_no_access' => true,
  163. 'phpdoc_no_alias_tag' => true,
  164. 'phpdoc_no_empty_return' => true,
  165. 'phpdoc_no_package' => true,
  166. 'phpdoc_no_useless_inheritdoc' => true,
  167. 'phpdoc_order' => true,
  168. 'phpdoc_return_self_reference' => true,
  169. 'phpdoc_scalar' => true,
  170. 'phpdoc_separation' => true,
  171. 'phpdoc_single_line_var_spacing' => true,
  172. 'phpdoc_summary' => true,
  173. 'phpdoc_to_comment' => false, // interferes with annotations
  174. 'phpdoc_to_param_type' => false, // Because experimental, but interesting for one shot use
  175. 'phpdoc_to_return_type' => false, // idem
  176. 'phpdoc_trim' => true,
  177. 'phpdoc_trim_consecutive_blank_line_separation' => true,
  178. 'phpdoc_types' => true,
  179. 'phpdoc_types_order' => true,
  180. 'phpdoc_var_annotation_correct_order' => true,
  181. 'phpdoc_var_without_name' => true,
  182. 'pow_to_exponentiation' => true,
  183. 'protected_to_private' => true,
  184. //'psr0' => true,
  185. //'psr4' => true,
  186. 'random_api_migration' => true,
  187. 'return_assignment' => false, // Sometimes useful for clarity or debug
  188. 'return_type_declaration' => true,
  189. 'self_accessor' => true,
  190. 'self_static_accessor' => true,
  191. 'semicolon_after_instruction' => false, // Buggy in `samples/index.php`
  192. 'set_type_to_cast' => true,
  193. 'short_scalar_cast' => true,
  194. 'simple_to_complex_string_variable' => false, // Would differ from TypeScript without obvious advantages
  195. 'simplified_null_return' => false, // Even if technically correct we prefer to be explicit
  196. 'single_blank_line_at_eof' => true,
  197. 'single_blank_line_before_namespace' => true,
  198. 'single_class_element_per_statement' => true,
  199. 'single_import_per_statement' => true,
  200. 'single_line_after_imports' => true,
  201. 'single_line_comment_style' => true,
  202. 'single_line_throw' => false, // I don't see any reason for having a special case for Exception
  203. 'single_quote' => true,
  204. 'single_trait_insert_per_statement' => true,
  205. 'space_after_semicolon' => true,
  206. 'standardize_increment' => true,
  207. 'standardize_not_equals' => true,
  208. 'static_lambda' => false, // Risky if we can't guarantee nobody use `bindTo()`
  209. 'strict_comparison' => false, // No, too dangerous to change that
  210. 'strict_param' => false, // No, too dangerous to change that
  211. 'string_line_ending' => true,
  212. 'switch_case_semicolon_to_colon' => true,
  213. 'switch_case_space' => true,
  214. 'ternary_operator_spaces' => true,
  215. 'ternary_to_null_coalescing' => true,
  216. 'trailing_comma_in_multiline' => true,
  217. 'trim_array_spaces' => true,
  218. 'unary_operator_spaces' => true,
  219. 'visibility_required' => ['elements' => ['property', 'method']], // not const
  220. 'void_return' => true,
  221. 'whitespace_after_comma_in_array' => true,
  222. 'yoda_style' => false,
  223. ]);
  224. return $config;