-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.php
130 lines (120 loc) · 4.6 KB
/
config.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
<?php declare(strict_types=1);
namespace MLL\PhpCsFixerConfig;
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
use PhpCsFixerCustomFixers;
/**
* Create a php-cs-fixer config that is enhanced with MLL rules.
*
* @param array<string, mixed> $ruleOverrides Custom rules that override the ones from this config
*/
function config(Finder $finder, array $ruleOverrides = []): Config
{
$safeRules = [
'@Symfony' => true,
'array_indentation' => true,
'assign_null_coalescing_to_coalesce_equal' => true,
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => [],
],
'combine_consecutive_unsets' => true,
'concat_space' => [
'spacing' => 'one',
],
'class_attributes_separation' => [
'elements' => [
'method' => 'one',
'property' => 'one',
],
],
'explicit_string_variable' => true,
'fully_qualified_strict_types' => false, // Messes up global config files where fully qualified class names are preferred
'heredoc_indentation' => false,
'list_syntax' => true,
'method_argument_space' => [
'on_multiline' => 'ensure_fully_multiline',
],
'method_chaining_indentation' => true,
'multiline_whitespace_before_semicolons' => [
'strategy' => 'no_multi_line',
],
'new_with_braces' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => true,
'no_useless_else' => true,
'not_operator_with_successor_space' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'operator_linebreak' => [
'position' => 'beginning',
],
'phpdoc_align' => false, // Messes with complex array shapes
'phpdoc_line_span' => [
'property' => 'single',
'const' => 'single',
'method' => 'single',
],
'phpdoc_no_alias_tag' => [
'replacements' => [
'type' => 'var',
'link' => 'see',
],
],
'phpdoc_order' => true,
'phpdoc_to_comment' => false, // Intermediary PHPDocs are sometimes useful to provide type assertions for PHPStan
'single_line_empty_body' => true,
'single_line_throw' => true,
// TODO add trailing commas everywhere when dropping PHP 7.4
'trailing_comma_in_multiline' => [
'after_heredoc' => true,
'elements' => [
// 'arguments',
'array_destructuring',
'arrays',
// 'match',
// 'parameters',
],
],
'yoda_style' => [ // Not necessary with static analysis, non-Yoda is more natural to write and read
'equal' => false,
'identical' => false,
'less_and_greater' => false,
],
PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer::name() => true,
PhpCsFixerCustomFixers\Fixer\DeclareAfterOpeningTagFixer::name() => true, // Use native rule when added with https://github.com/PHP-CS-Fixer/PHP-CS-Fixer/issues/2062
PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer::name() => true,
];
return (new Config())
->registerCustomFixers(new PhpCsFixerCustomFixers\Fixers())
->setFinder($finder)
->setRules(array_merge($safeRules, $ruleOverrides));
}
/**
* Create a php-cs-fixer config with risky rules.
*
* @param array<string, mixed> $ruleOverrides Custom rules that override the ones from this config
*/
function risky(Finder $finder, array $ruleOverrides = []): Config
{
$riskyRules = [
'declare_strict_types' => true,
// Technically not strict rules, but they go hand-in-hand with declare_strict_types
// to achieve a first line of: "<?php declare(strict_types=1);" with no extra newlines
// see https://github.com/FriendsOfPHP/PHP-CS-Fixer/issues/4252
'linebreak_after_opening_tag' => false,
'blank_line_after_opening_tag' => false,
'logical_operators' => true,
'modernize_types_casting' => true,
'use_arrow_functions' => true,
// We invert the usual behavior of this rule by including no functions,
// which in turn causes the "strict" option to remove backslashes everywhere.
'native_function_invocation' => [
'include' => [],
'strict' => true,
],
];
return config($finder, array_merge($riskyRules, $ruleOverrides))
->setRiskyAllowed(true);
}