-
Notifications
You must be signed in to change notification settings - Fork 0
/
.php-cs-fixer.dist.php
147 lines (144 loc) · 5.03 KB
/
.php-cs-fixer.dist.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
<?php
$finder = PhpCsFixer\Finder::create()
->in('app/')
->in('config/')
->in('database/')
->in('routes/')
->in('tests/');
/**
* Rule detail in https://mlocati.github.io/php-cs-fixer-configurator
* Or run command:
* php-cs-fixer describe @PSR12
* php-cs-fixer describe class_attributes_separation
*/
return (new PhpCsFixer\Config())
->setRules([
'@PSR12' => true,
'class_definition' => [
'space_before_parenthesis' => false,
],
'control_structure_braces' => true,
'control_structure_continuation_position' => [
'position' => 'same_line',
],
'no_multiple_statements_per_line' => true,
'declare_parentheses' => true,
'braces_position' => [
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
'anonymous_classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
'anonymous_functions_opening_brace' => 'same_line',
],
'new_with_parentheses' => [
'anonymous_class' => false,
'named_class' => true,
],
// Use single quote when possible, 'string', "example with 'single-quotes'"
'single_quote' => true,
// Surround operators +, -, *, /, &&, ||, ... by space
'binary_operator_spaces' => [
'default' => 'single_space',
],
'array_indentation' => true,
'array_syntax' => [
'syntax' => 'short',
],
'list_syntax' => [
'syntax' => 'short',
],
'whitespace_after_comma_in_array' => [
'ensure_single_space' => true,
],
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'no_spaces_around_offset' => true,
'no_multiline_whitespace_around_double_arrow' => true,
'trim_array_spaces' => true,
/*
Bad: function foo(int | string $x)
Good: function foo(int|string $x)
Bad: catch (ErrorA | ErrorB $e)
Good: catch (ErrorA|ErrorB $e)
*/
'types_spaces' => true,
'unary_operator_spaces' => true,
// (int) $b instead of (int)$b
'cast_spaces' => [
'space' => 'single',
],
'method_chaining_indentation' => true,
'no_trailing_comma_in_singleline' => true,
// Multi-line arrays, arguments list, parameters list and `match` expressions must have a trailing comma
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => ['arrays', 'match', 'arguments', 'parameters'],
],
// Use ??= when possible
'assign_null_coalescing_to_coalesce_equal' => true,
// Use ?? instead of isset
'ternary_to_null_coalescing' => true,
// Must have one blank line before continue, return, throw
'blank_line_before_statement' => [
'statements' => ['continue', 'return', 'throw'],
],
// Class constants, properties, methods must be separated with one blank line.
'class_attributes_separation' => [
'elements' => [
'const' => 'one',
'property' => 'one',
'method' => 'one',
'trait_import' => 'none',
],
],
'class_reference_name_casing' => true,
'object_operator_without_whitespace' => true,
'type_declaration_spaces' => [
'elements' => [
'function',
'property',
],
],
'lambda_not_used_import' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'no_empty_statement' => true,
'no_extra_blank_lines' => [
'tokens' => [
'extra',
'throw',
'use',
'return',
'curly_brace_block',
'parenthesis_brace_block',
'square_brace_block',
'switch',
'case',
'default',
],
],
'no_unneeded_control_parentheses' => [
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
],
'no_unused_imports' => true,
'no_useless_return' => true,
'no_superfluous_elseif' => true,
'no_useless_else' => true,
'phpdoc_indent' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_scalar' => true,
'phpdoc_single_line_var_spacing' => true,
'phpdoc_tag_type' => [
'tags' => [
'inheritdoc' => 'inline',
],
],
'phpdoc_trim' => true,
'no_superfluous_phpdoc_tags' => true,
'phpdoc_var_without_name' => true,
'php_unit_method_casing' => [
'case' => 'snake_case',
],
])
->setFinder($finder);