1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* @link http://www.yiiframework.com/ |
4
|
|
|
* @copyright Copyright (c) 2008 Yii Software LLC |
5
|
|
|
* @license http://www.yiiframework.com/license/ |
6
|
|
|
*/ |
7
|
|
|
|
8
|
|
|
namespace yii\cs; |
9
|
|
|
|
10
|
|
|
use PhpCsFixer\Config; |
11
|
|
|
use yii\helpers\ArrayHelper; |
12
|
|
|
|
13
|
|
|
/** |
14
|
|
|
* Basic rules used by Yii 2 ecosystem. |
15
|
|
|
* |
16
|
|
|
* @author Robert Korulczyk <[email protected]> |
17
|
|
|
* @since 2.0.0 |
18
|
|
|
*/ |
19
|
|
|
class YiiConfig extends Config |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* {@inheritdoc} |
23
|
|
|
*/ |
24
|
|
|
public function __construct($name = 'yii-cs-config') |
25
|
|
|
{ |
26
|
|
|
parent::__construct($name); |
27
|
|
|
|
28
|
|
|
$this->setRiskyAllowed(true); |
29
|
|
|
|
30
|
|
|
$this->setRules([ |
31
|
|
|
'@PSR2' => true, |
32
|
|
|
'array_syntax' => [ |
33
|
|
|
'syntax' => 'short', |
34
|
|
|
], |
35
|
|
|
'binary_operator_spaces' => [ |
36
|
|
|
'align_double_arrow' => false, |
37
|
|
|
'align_equals' => false, |
38
|
|
|
], |
39
|
|
|
'blank_line_after_opening_tag' => true, |
40
|
|
|
'cast_spaces' => true, |
41
|
|
|
'concat_space' => [ |
42
|
|
|
'spacing' => 'one', |
43
|
|
|
], |
44
|
|
|
'dir_constant' => true, |
45
|
|
|
'ereg_to_preg' => true, |
46
|
|
|
'function_typehint_space' => true, |
47
|
|
|
'hash_to_slash_comment' => true, |
48
|
|
|
'include' => true, |
49
|
|
|
'heredoc_to_nowdoc' => true, |
50
|
|
|
'is_null' => [ |
51
|
|
|
'use_yoda_style' => false, |
52
|
|
|
], |
53
|
|
|
'linebreak_after_opening_tag' => true, |
54
|
|
|
'lowercase_cast' => true, |
55
|
|
|
'magic_constant_casing' => true, |
56
|
|
|
// 'mb_str_functions' => true, // needs more discussion |
57
|
|
|
// 'method_separation' => true, // conflicts with current Yii style with double line between properties and methods |
58
|
|
|
'modernize_types_casting' => true, |
59
|
|
|
'native_function_casing' => true, |
60
|
|
|
'new_with_braces' => true, |
61
|
|
|
'no_alias_functions' => true, |
62
|
|
|
'no_blank_lines_after_class_opening' => true, |
63
|
|
|
'no_blank_lines_after_phpdoc' => true, |
64
|
|
|
'no_empty_comment' => true, |
65
|
|
|
'no_empty_phpdoc' => true, |
66
|
|
|
'no_empty_statement' => true, |
67
|
|
|
'no_extra_consecutive_blank_lines' => [ |
68
|
|
|
'tokens' => [ |
69
|
|
|
'break', |
70
|
|
|
'continue', |
71
|
|
|
// 'extra', // conflicts with current Yii style with double line between properties and methods |
72
|
|
|
'return', |
73
|
|
|
'throw', |
74
|
|
|
'use', |
75
|
|
|
'use_trait', |
76
|
|
|
// 'curly_brace_block', // breaks namespaces blocks |
77
|
|
|
'parenthesis_brace_block', |
78
|
|
|
'square_brace_block', |
79
|
|
|
], |
80
|
|
|
], |
81
|
|
|
'no_leading_import_slash' => true, |
82
|
|
|
'no_leading_namespace_whitespace' => true, |
83
|
|
|
'no_mixed_echo_print' => true, |
84
|
|
|
'no_multiline_whitespace_around_double_arrow' => true, |
85
|
|
|
'no_multiline_whitespace_before_semicolons' => true, |
86
|
|
|
'no_php4_constructor' => true, |
87
|
|
|
'no_short_bool_cast' => true, |
88
|
|
|
'no_singleline_whitespace_before_semicolons' => true, |
89
|
|
|
'no_spaces_around_offset' => true, |
90
|
|
|
'no_trailing_comma_in_list_call' => true, |
91
|
|
|
'no_trailing_comma_in_singleline_array' => true, |
92
|
|
|
'no_unneeded_control_parentheses' => true, |
93
|
|
|
'no_unused_imports' => true, |
94
|
|
|
'no_useless_else' => true, |
95
|
|
|
'no_useless_return' => true, |
96
|
|
|
'no_whitespace_before_comma_in_array' => true, |
97
|
|
|
'no_whitespace_in_blank_line' => true, |
98
|
|
|
'non_printable_character' => true, |
99
|
|
|
'normalize_index_brace' => true, |
100
|
|
|
'object_operator_without_whitespace' => true, |
101
|
|
|
// 'ordered_class_elements' => [ // needs more discussion |
102
|
|
|
// 'order' => [ |
103
|
|
|
// 'use_trait', |
104
|
|
|
// 'constant_public', |
105
|
|
|
// 'constant_protected', |
106
|
|
|
// 'constant_private', |
107
|
|
|
// 'property_public', |
108
|
|
|
// 'property_protected', |
109
|
|
|
// 'property_private', |
110
|
|
|
// 'construct', |
111
|
|
|
// 'destruct', |
112
|
|
|
// 'magic', |
113
|
|
|
// ], |
114
|
|
|
// ], |
115
|
|
|
'ordered_imports' => [ |
116
|
|
|
'sortAlgorithm' => 'alpha', |
117
|
|
|
'importsOrder' => [ |
118
|
|
|
'const', |
119
|
|
|
'function', |
120
|
|
|
'class', |
121
|
|
|
], |
122
|
|
|
], |
123
|
|
|
'php_unit_construct' => true, |
124
|
|
|
'php_unit_dedicate_assert' => true, |
125
|
|
|
'php_unit_fqcn_annotation' => true, |
126
|
|
|
// 'php_unit_strict' => true, // needs more attention |
127
|
|
|
'phpdoc_add_missing_param_annotation' => true, |
128
|
|
|
'phpdoc_indent' => true, |
129
|
|
|
// 'phpdoc_inline_tag' => true, // see https://github.com/yiisoft/yii2/issues/11635 |
130
|
|
|
'phpdoc_no_access' => true, |
131
|
|
|
'phpdoc_no_empty_return' => true, |
132
|
|
|
'phpdoc_no_package' => true, |
133
|
|
|
'phpdoc_no_useless_inheritdoc' => true, |
134
|
|
|
// 'phpdoc_order', // may be useful, but should be configurable: https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/1602 |
135
|
|
|
'phpdoc_return_self_reference' => true, |
136
|
|
|
'phpdoc_scalar' => true, |
137
|
|
|
'phpdoc_single_line_var_spacing' => true, |
138
|
|
|
'phpdoc_summary' => true, |
139
|
|
|
// 'phpdoc_to_comment' => true, // breaks phpdoc for define('CONSTANT', $value); |
140
|
|
|
'phpdoc_trim' => true, |
141
|
|
|
'phpdoc_types' => true, |
142
|
|
|
'phpdoc_var_without_name' => true, |
143
|
|
|
'protected_to_private' => true, |
144
|
|
|
'psr4' => true, |
145
|
|
|
'self_accessor' => true, |
146
|
|
|
'short_scalar_cast' => true, |
147
|
|
|
'single_blank_line_before_namespace' => true, |
148
|
|
|
'single_quote' => true, |
149
|
|
|
'standardize_not_equals' => true, |
150
|
|
|
'ternary_operator_spaces' => true, |
151
|
|
|
'trailing_comma_in_multiline_array' => true, |
152
|
|
|
'trim_array_spaces' => true, |
153
|
|
|
'unary_operator_spaces' => true, |
154
|
|
|
'whitespace_after_comma_in_array' => true, |
155
|
|
|
]); |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
/** |
159
|
|
|
* Merge current rules' config with provided list of rules. |
160
|
|
|
* |
161
|
|
|
* @param array $rules |
162
|
|
|
* @return $this |
163
|
|
|
* @see setRules() |
164
|
|
|
* @see ArrayHelper::merge() |
165
|
|
|
*/ |
166
|
|
|
public function mergeRules(array $rules) |
167
|
|
|
{ |
168
|
|
|
$this->setRules(ArrayHelper::merge($this->getRules(), $rules)); |
169
|
|
|
|
170
|
|
|
return $this; |
171
|
|
|
} |
172
|
|
|
} |
173
|
|
|
|