Skip to content

Commit ba1869d

Browse files
committed
added php-cs-fixer
1 parent 6cd419f commit ba1869d

File tree

2 files changed

+175
-1
lines changed

2 files changed

+175
-1
lines changed

.php-cs-fixer.dist.php

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
<?php
2+
3+
use PhpCsFixer\Config;
4+
use PhpCsFixer\Finder;
5+
6+
$rules = [
7+
'array_syntax' => ['syntax' => 'short'],
8+
9+
'no_unused_imports' => true,
10+
'blank_line_after_namespace' => true,
11+
'blank_line_after_opening_tag' => true,
12+
'braces' => true,
13+
'cast_spaces' => true,
14+
'concat_space' => [
15+
'spacing' => 'none',
16+
],
17+
'declare_equal_normalize' => true,
18+
'elseif' => true,
19+
'encoding' => true,
20+
'full_opening_tag' => true,
21+
'fully_qualified_strict_types' => true, // added by Shift
22+
'function_declaration' => true,
23+
'function_typehint_space' => true,
24+
'heredoc_to_nowdoc' => true,
25+
'include' => true,
26+
'increment_style' => ['style' => 'post'],
27+
'indentation_type' => true,
28+
'linebreak_after_opening_tag' => true,
29+
'line_ending' => true,
30+
'lowercase_cast' => true,
31+
'lowercase_keywords' => true,
32+
'lowercase_static_reference' => true, // added from Symfony
33+
'magic_method_casing' => true, // added from Symfony
34+
'magic_constant_casing' => true,
35+
'method_argument_space' => true,
36+
'native_function_casing' => true,
37+
'no_alias_functions' => true,
38+
'no_extra_blank_lines' => [
39+
'tokens' => [
40+
'extra',
41+
'throw',
42+
'use',
43+
],
44+
],
45+
'no_blank_lines_after_class_opening' => true,
46+
'no_blank_lines_after_phpdoc' => true,
47+
'no_closing_tag' => true,
48+
'no_empty_phpdoc' => true,
49+
'no_empty_statement' => true,
50+
'no_leading_import_slash' => true,
51+
'no_leading_namespace_whitespace' => true,
52+
'no_mixed_echo_print' => [
53+
'use' => 'echo',
54+
],
55+
'no_multiline_whitespace_around_double_arrow' => true,
56+
'multiline_whitespace_before_semicolons' => [
57+
'strategy' => 'no_multi_line',
58+
],
59+
'no_short_bool_cast' => true,
60+
'no_singleline_whitespace_before_semicolons' => true,
61+
'no_spaces_after_function_name' => true,
62+
'no_spaces_inside_parenthesis' => true,
63+
'no_trailing_comma_in_list_call' => true,
64+
'no_trailing_comma_in_singleline_array' => true,
65+
'no_trailing_whitespace' => true,
66+
'no_trailing_whitespace_in_comment' => true,
67+
'no_unreachable_default_argument_value' => true,
68+
'no_useless_return' => true,
69+
'no_whitespace_before_comma_in_array' => true,
70+
'no_whitespace_in_blank_line' => true,
71+
'normalize_index_brace' => true,
72+
'not_operator_with_successor_space' => true,
73+
'object_operator_without_whitespace' => true,
74+
'phpdoc_indent' => true,
75+
'phpdoc_no_access' => true,
76+
'phpdoc_no_package' => true,
77+
'phpdoc_no_useless_inheritdoc' => true,
78+
'phpdoc_scalar' => true,
79+
'phpdoc_single_line_var_spacing' => true,
80+
'phpdoc_summary' => true,
81+
'phpdoc_to_comment' => true,
82+
'phpdoc_trim' => true,
83+
'phpdoc_types' => true,
84+
'phpdoc_var_without_name' => true,
85+
'self_accessor' => true,
86+
'short_scalar_cast' => true,
87+
'simplified_null_return' => false, // disabled by Shift
88+
'single_blank_line_at_eof' => true,
89+
'single_blank_line_before_namespace' => true,
90+
'single_import_per_statement' => true,
91+
'single_line_after_imports' => true,
92+
'single_line_comment_style' => [
93+
'comment_types' => ['hash'],
94+
],
95+
'single_quote' => true,
96+
'space_after_semicolon' => true,
97+
'standardize_not_equals' => true,
98+
'switch_case_semicolon_to_colon' => true,
99+
'switch_case_space' => true,
100+
'ternary_operator_spaces' => true,
101+
'trim_array_spaces' => false,
102+
'unary_operator_spaces' => true,
103+
'whitespace_after_comma_in_array' => true,
104+
105+
// php-cs-fixer 3: Renamed rules
106+
'constant_case' => ['case' => 'lower'],
107+
'general_phpdoc_tag_rename' => true,
108+
'phpdoc_inline_tag_normalizer' => true,
109+
'phpdoc_tag_type' => true,
110+
'psr_autoloading' => true,
111+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
112+
113+
// php-cs-fixer 3: Changed options
114+
'binary_operator_spaces' => [
115+
'default' => 'align_single_space',
116+
'operators' => [
117+
'=>' => 'align_single_space',
118+
'=' => 'align_single_space',
119+
],
120+
],
121+
'blank_line_before_statement' => [
122+
'statements' => ['return'],
123+
],
124+
'class_attributes_separation' => [
125+
'elements' => [
126+
'const' => 'none',
127+
'method' => 'one',
128+
'property' => 'none',
129+
'trait_import' => 'none',
130+
],
131+
],
132+
'class_definition' => [
133+
'multi_line_extends_each_single_line' => true,
134+
'single_item_single_line' => true,
135+
'single_line' => true,
136+
],
137+
'ordered_imports' => [
138+
'sort_algorithm' => 'alpha',
139+
],
140+
141+
// php-cs-fixer 3: Removed rootless options (*)
142+
'no_unneeded_control_parentheses' => [
143+
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
144+
],
145+
'no_spaces_around_offset' => [
146+
'positions' => ['inside', 'outside'],
147+
],
148+
'visibility_required' => [
149+
'elements' => ['property', 'method', 'const'],
150+
],
151+
152+
];
153+
154+
$finder = Finder::create()
155+
->in([
156+
__DIR__.'/src',
157+
__DIR__.'/config',
158+
__DIR__.'/tests',
159+
])
160+
->name('*.php')
161+
->ignoreDotFiles(true)
162+
->ignoreVCS(true);
163+
164+
return (new Config())
165+
->setFinder($finder)
166+
->setRules($rules)
167+
->setRiskyAllowed(true)
168+
->setUsingCache(true);

composer.json

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
"require-dev": {
1212
"orchestra/testbench": "^5.0|^6.23|^7.0",
1313
"pestphp/pest": "^1.21",
14-
"pestphp/pest-plugin-laravel": "^1.1"
14+
"pestphp/pest-plugin-laravel": "^1.1",
15+
"friendsofphp/php-cs-fixer": "^3.9"
1516
},
1617
"autoload": {
1718
"psr-4": {
@@ -30,5 +31,10 @@
3031
"Dcblogdev\\DbSync\\DbSyncServiceProvider"
3132
]
3233
}
34+
},
35+
"config": {
36+
"allow-plugins": {
37+
"pestphp/pest-plugin": true
38+
}
3339
}
3440
}

0 commit comments

Comments
 (0)