Skip to content

Commit e6188df

Browse files
committed
Add a shared php-cs-fixer config
1 parent 44f398f commit e6188df

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

.php-cs-fixer-rules.php

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
<?php declare(strict_types=1);
2+
3+
/**
4+
* Shared PHP-CS-Fixer rules for PER projects.
5+
* @see https://localheinz.com/articles/2023/03/10/sharing-configurations-for-php-cs-fixer-across-projects/
6+
* How to use:
7+
* $rules = require __DIR__.'/vendor/interaction-design-foundation/php-cs-fixer-rules.php';
8+
* $config->setRules($rules);
9+
*/
10+
return [
11+
// Basic PER Coding Style 2.0 ruleset plus our overrides for it, see https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/blob/master/doc/ruleSets/PER-CS2.0.rst
12+
'@PER-CS2.0' => true, // https://www.php-fig.org/per/coding-style/}
13+
// overrides for PER-CS2.0
14+
'concat_space' => ['spacing' => 'none'], // make strings shorter "'hello' . $name . '!'" => "'hello'.$name.'!'"
15+
'blank_line_after_opening_tag' => false, // it makes "<?php declare(strict_types=1);" multiline (and more verbose)
16+
17+
// Additional rules on the top of PER-CS2
18+
// Please keep these rules alphabetically
19+
'align_multiline_comment' => ['comment_type' => 'phpdocs_only'],
20+
'array_indentation' => true,
21+
'assign_null_coalescing_to_coalesce_equal' => true,
22+
'binary_operator_spaces' => ['default' => 'single_space'],
23+
'cast_spaces' => ['space' => 'single'],
24+
'class_attributes_separation' => ['elements' => ['method' => 'one']],
25+
'declare_strict_types' => true,
26+
'explicit_string_variable' => true,
27+
'final_public_method_for_abstract_class' => true,
28+
'general_phpdoc_annotation_remove' => [
29+
'annotations' => [
30+
'api',
31+
'access',
32+
'author',
33+
'category',
34+
'copyright',
35+
'created',
36+
'license',
37+
'link',
38+
'package',
39+
'since',
40+
'subpackage',
41+
'version',
42+
],
43+
],
44+
'modernize_types_casting' => true,
45+
'mb_str_functions' => true,
46+
'no_alias_functions' => true,
47+
'no_binary_string' => true,
48+
'no_empty_comment' => true,
49+
'no_empty_phpdoc' => true,
50+
'no_empty_statement' => true,
51+
'no_extra_blank_lines' => ['tokens' => ['extra', 'curly_brace_block']],
52+
'no_homoglyph_names' => true,
53+
'no_leading_namespace_whitespace' => true,
54+
'no_mixed_echo_print' => true,
55+
'no_short_bool_cast' => true,
56+
'no_singleline_whitespace_before_semicolons' => true,
57+
'no_spaces_around_offset' => true,
58+
'no_trailing_comma_in_singleline' => false, // it's a good marker that there are more elements in an array
59+
'no_unneeded_braces' => true,
60+
'no_unneeded_control_parentheses' => true,
61+
'no_unneeded_final_method' => true,
62+
'no_unreachable_default_argument_value' => true,
63+
'no_unused_imports' => true,
64+
'no_useless_concat_operator' => true,
65+
'no_useless_return' => true,
66+
'no_whitespace_before_comma_in_array' => true,
67+
'normalize_index_brace' => true,
68+
'nullable_type_declaration' => ['syntax' => 'question_mark'],
69+
'object_operator_without_whitespace' => true,
70+
/*
71+
* @see https://github.com/slevomat/coding-standard/issues/1620#issuecomment-1758006718
72+
* 'ordered_class_elements' => [
73+
'order' => [
74+
'use_trait',
75+
'constant',
76+
'case', // for enums only
77+
'property',
78+
'method',
79+
]
80+
],*/
81+
'php_unit_construct' => true,
82+
'php_unit_dedicate_assert' => ['target' => 'newest'],
83+
'php_unit_expectation' => true,
84+
'php_unit_fqcn_annotation' => true,
85+
'php_unit_method_casing' => ['case' => 'snake_case'],
86+
'php_unit_no_expectation_annotation' => true,
87+
'php_unit_set_up_tear_down_visibility' => true,
88+
'php_unit_strict' => true,
89+
'php_unit_test_annotation' => ['style' => 'annotation'],
90+
'php_unit_test_class_requires_covers' => true,
91+
'phpdoc_align' => ['align' => 'left'],
92+
'phpdoc_array_type' => true,
93+
'phpdoc_indent' => true,
94+
'phpdoc_line_span' => ['const' => 'single', 'property' => 'single', 'method' => 'single'],
95+
'phpdoc_param_order' => true,
96+
'phpdoc_scalar' => true,
97+
'phpdoc_single_line_var_spacing' => true,
98+
'phpdoc_tag_casing' => true,
99+
'phpdoc_types' => true,
100+
'protected_to_private' => true,
101+
'psr_autoloading' => true,
102+
'self_accessor' => true,
103+
'self_static_accessor' => true,
104+
'single_line_comment_spacing' => true,
105+
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']],
106+
'space_after_semicolon' => true,
107+
'standardize_not_equals' => true,
108+
'strict_param' => true,
109+
'ternary_to_null_coalescing' => true,
110+
'trim_array_spaces' => true,
111+
'trailing_comma_in_multiline' => true,
112+
'type_declaration_spaces' => true,
113+
'types_spaces' => ['space' => 'single'],
114+
'whitespace_after_comma_in_array' => true,
115+
'yoda_style' => ['equal' => false, 'identical' => false, 'less_and_greater' => false],
116+
];

0 commit comments

Comments
 (0)