Skip to content

Commit 4616f44

Browse files
Add PHP CS Fixer and update composer.json
1 parent da2b8d1 commit 4616f44

File tree

2 files changed

+260
-6
lines changed

2 files changed

+260
-6
lines changed

.php-cs-fixer.dist.php

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
<?php
2+
3+
// Last reviewed: v2.19 (Testament)
4+
// Based on https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
5+
6+
use PhpCsFixer\Config;
7+
use PhpCsFixer\Finder;
8+
9+
$rules = [
10+
'@PSR1' => true,
11+
'@PSR2' => true,
12+
'@PhpCsFixer' => true,
13+
'@Symfony' => true,
14+
'@PHP70Migration' => true,
15+
'@PHP70Migration:risky' => true,
16+
'@PHP71Migration' => true,
17+
'@PHP71Migration:risky' => true,
18+
'@PHP73Migration' => true,
19+
'@PHPUnit75Migration:risky' => true,
20+
'final_class' => false,
21+
'new_with_braces' => false,
22+
'strict_comparison' => true,
23+
'list_syntax' => ['syntax' => 'short'],
24+
'mb_str_functions' => true,
25+
'class_attributes_separation' => [
26+
'elements' => [
27+
'method' => 'one',
28+
],
29+
],
30+
'no_extra_blank_lines' => [
31+
'tokens' => [
32+
'break',
33+
'continue',
34+
'curly_brace_block',
35+
'extra',
36+
'parenthesis_brace_block',
37+
'return',
38+
'square_brace_block',
39+
'throw',
40+
'use',
41+
'use_trait',
42+
'switch',
43+
44+
'case',
45+
'default',
46+
],
47+
],
48+
'no_blank_lines_before_namespace' => false,
49+
'nullable_type_declaration_for_default_null_value' => true,
50+
'increment_style' => ['style' => 'pre'],
51+
'self_static_accessor' => true,
52+
'static_lambda' => false,
53+
'no_empty_phpdoc' => true,
54+
'no_superfluous_phpdoc_tags' => [
55+
'remove_inheritdoc' => true,
56+
],
57+
'phpdoc_line_span' => [
58+
'const' => 'multi',
59+
'method' => 'multi',
60+
'property' => 'multi',
61+
],
62+
'general_phpdoc_tag_rename' => true,
63+
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
64+
'phpdoc_align' => ['align' => 'left'],
65+
'phpdoc_indent' => true,
66+
'phpdoc_inline_tag_normalizer' => true,
67+
'phpdoc_no_access' => true,
68+
'phpdoc_no_empty_return' => false,
69+
'phpdoc_no_package' => true,
70+
'phpdoc_no_useless_inheritdoc' => true,
71+
'phpdoc_order' => true,
72+
'phpdoc_order_by_value' => false,
73+
'phpdoc_scalar' => true,
74+
'phpdoc_single_line_var_spacing' => true,
75+
'phpdoc_summary' => true,
76+
'phpdoc_tag_casing' => ['tags' => ['inheritDoc']],
77+
'phpdoc_tag_type' => true,
78+
'phpdoc_to_comment' => true,
79+
'phpdoc_trim' => true,
80+
'phpdoc_types' => ['groups' => ['simple', 'alias']],
81+
'phpdoc_types_order' => ['null_adjustment' => 'always_last'],
82+
'phpdoc_var_annotation_correct_order' => true,
83+
'phpdoc_var_without_name' => true,
84+
'align_multiline_comment' => ['comment_type' => 'phpdocs_like'],
85+
'php_unit_test_class_requires_covers' => false,
86+
'php_unit_internal_class' => false,
87+
'yoda_style' => false,
88+
'ordered_class_elements' => [
89+
'order' => [
90+
'use_trait',
91+
'constant_public',
92+
'constant_protected',
93+
'constant_private',
94+
95+
'property_static',
96+
'property_public_static',
97+
'property_protected_static',
98+
'property_private_static',
99+
100+
'property',
101+
'property_public',
102+
'property_protected',
103+
'property_private',
104+
105+
'construct',
106+
'destruct',
107+
'magic',
108+
109+
'method_static',
110+
'method_public_abstract_static',
111+
'method_public_static',
112+
'method_protected_abstract_static',
113+
'method_protected_static',
114+
'method_private_static',
115+
'method_public_abstract',
116+
'method_public',
117+
'method_protected_abstract',
118+
'method_protected',
119+
'method_private',
120+
],
121+
],
122+
'array_syntax' => ['syntax' => 'short'],
123+
'blank_line_after_namespace' => true,
124+
'blank_line_after_opening_tag' => true,
125+
'braces' => true,
126+
'cast_spaces' => true,
127+
'concat_space' => [
128+
'spacing' => 'none',
129+
],
130+
'declare_equal_normalize' => true,
131+
'elseif' => true,
132+
'encoding' => true,
133+
'full_opening_tag' => true,
134+
'fully_qualified_strict_types' => true, // added by Shift
135+
'function_declaration' => true,
136+
'function_typehint_space' => true,
137+
'heredoc_to_nowdoc' => true,
138+
'include' => true,
139+
'indentation_type' => true,
140+
'linebreak_after_opening_tag' => true,
141+
'line_ending' => true,
142+
'lowercase_cast' => true,
143+
'lowercase_keywords' => true,
144+
'lowercase_static_reference' => true, // added from Symfony
145+
'magic_method_casing' => true, // added from Symfony
146+
'magic_constant_casing' => true,
147+
'method_argument_space' => true,
148+
'native_function_casing' => true,
149+
'no_alias_functions' => false,
150+
'no_blank_lines_after_class_opening' => true,
151+
'no_blank_lines_after_phpdoc' => true,
152+
'no_closing_tag' => true,
153+
'no_empty_statement' => true,
154+
'no_leading_import_slash' => true,
155+
'no_leading_namespace_whitespace' => true,
156+
'no_mixed_echo_print' => [
157+
'use' => 'echo',
158+
],
159+
'no_multiline_whitespace_around_double_arrow' => true,
160+
'multiline_whitespace_before_semicolons' => [
161+
'strategy' => 'no_multi_line',
162+
],
163+
'no_short_bool_cast' => true,
164+
'no_singleline_whitespace_before_semicolons' => true,
165+
'no_spaces_after_function_name' => true,
166+
'no_spaces_inside_parenthesis' => true,
167+
'no_trailing_comma_in_list_call' => false,
168+
'no_trailing_comma_in_singleline_array' => true,
169+
'no_trailing_whitespace' => true,
170+
'no_trailing_whitespace_in_comment' => true,
171+
'no_unreachable_default_argument_value' => true,
172+
'no_useless_return' => true,
173+
'no_whitespace_before_comma_in_array' => true,
174+
'no_whitespace_in_blank_line' => true,
175+
'normalize_index_brace' => true,
176+
'not_operator_with_successor_space' => true,
177+
'object_operator_without_whitespace' => true,
178+
'self_accessor' => false,
179+
'short_scalar_cast' => true,
180+
'simplified_null_return' => false, // disabled by Shift
181+
'single_blank_line_at_eof' => true,
182+
'single_blank_line_before_namespace' => true,
183+
'single_import_per_statement' => true,
184+
'single_line_after_imports' => true,
185+
'single_line_comment_style' => [
186+
'comment_types' => ['hash'],
187+
],
188+
'single_quote' => true,
189+
'space_after_semicolon' => true,
190+
'standardize_not_equals' => true,
191+
'switch_case_semicolon_to_colon' => true,
192+
'switch_case_space' => true,
193+
'ternary_operator_spaces' => true,
194+
'trim_array_spaces' => true,
195+
'unary_operator_spaces' => true,
196+
'whitespace_after_comma_in_array' => true,
197+
'constant_case' => ['case' => 'lower'],
198+
'psr_autoloading' => true,
199+
'trailing_comma_in_multiline' => ['elements' => ['arrays']],
200+
'binary_operator_spaces' => [
201+
'default' => 'single_space',
202+
],
203+
'types_spaces' => [
204+
'space' => 'none',
205+
],
206+
'blank_line_before_statement' => [
207+
'statements' => ['return'],
208+
],
209+
'class_definition' => [
210+
'multi_line_extends_each_single_line' => true,
211+
'single_item_single_line' => true,
212+
'single_line' => true,
213+
],
214+
'ordered_imports' => [
215+
'sort_algorithm' => 'alpha',
216+
],
217+
'no_unneeded_control_parentheses' => [
218+
'statements' => ['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case', 'yield'],
219+
],
220+
'no_spaces_around_offset' => [
221+
'positions' => ['inside', 'outside'],
222+
],
223+
'visibility_required' => [
224+
'elements' => ['property', 'method', 'const'],
225+
],
226+
];
227+
228+
$finder = Finder::create()
229+
->in([
230+
__DIR__.'/src',
231+
__DIR__.'/tests',
232+
])
233+
->name('*.php')
234+
->notName('*.blade.php')
235+
->ignoreDotFiles(true)
236+
->ignoreVCS(true);
237+
238+
return (new Config)
239+
->setRules($rules)
240+
->setFinder($finder)
241+
->setRiskyAllowed(true)
242+
->setUsingCache(true);

composer.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@
2222
"php": "~8.0|~8.1"
2323
},
2424
"require-dev": {
25-
"phpunit/phpunit": "^9.5",
26-
"ext-mbstring": "*"
25+
"ext-mbstring": "*",
26+
"friendsofphp/php-cs-fixer": "^3.7",
27+
"phpunit/phpunit": "^9.5"
2728
},
2829
"autoload": {
2930
"psr-4": {
@@ -41,15 +42,26 @@
4142
"config": {
4243
"sort-packages": true
4344
},
45+
"minimum-stability": "dev",
46+
"prefer-stable": true,
4447
"scripts": {
48+
"composer:validate": "@composer validate --strict --ansi",
4549
"test": "vendor/bin/phpunit",
46-
"test-lowest": [
47-
"composer update --prefer-lowest --prefer-dist --no-interaction --ansi",
50+
"lint": "vendor/bin/php-cs-fixer fix --dry-run --diff --ansi",
51+
"fix": "vendor/bin/php-cs-fixer fix --ansi",
52+
"check": [
53+
"@composer:validate",
54+
"@lint",
4855
"@test"
4956
],
50-
"test-stable": [
57+
"check:lowest": [
58+
"composer update --prefer-lowest --prefer-dist --no-interaction --ansi",
59+
"@check"
60+
],
61+
"check:stable": [
5162
"composer update --prefer-stable --prefer-dist --no-interaction --ansi",
52-
"@test"
63+
"@check"
5364
]
5465
}
5566
}
67+

0 commit comments

Comments
 (0)