Skip to content

Commit 6437a6d

Browse files
Merge pull request #125 from VincentLanglet/ruleset
💄 Improve ruleset
2 parents 5d37c37 + acca8ed commit 6437a6d

File tree

2 files changed

+164
-65
lines changed

2 files changed

+164
-65
lines changed

SymfonyCustom/Helpers/SniffHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ public static function isGlobalUse(File $phpcsFile, int $stackPtr): bool
195195
public static function parseTypeHint(string $content): array
196196
{
197197
preg_match(
198-
'{^'.SniffHelper::REGEX_TYPES.'(?<space>[\s\t]*)?(?<description>.*)?$}six',
198+
'{^'.self::REGEX_TYPES.'(?<space>[\s\t]*)?(?<description>.*)?$}six',
199199
$content,
200200
$matches
201201
);

SymfonyCustom/ruleset.xml

Lines changed: 163 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
<arg name="extensions" value="php,inc"/>
77
<exclude-pattern>*/vendor/*</exclude-pattern>
88

9-
<!-- ************** -->
9+
<!-- *************** -->
1010
<!-- *** PSR12 *** -->
11-
<!-- ************** -->
11+
<!-- *************** -->
1212

1313
<!-- Include the PSR-12 (so PSR-1) standard without the file length limit -->
1414
<rule ref="PSR12">
@@ -18,118 +18,217 @@
1818
</rule>
1919
<!-- Instead of PSR12.ControlStructures.ControlStructureSpacing -->
2020
<rule ref="PSR2.ControlStructures.ControlStructureSpacing"/>
21-
<!-- Instead of PSR12.Operators.OperatorSpacing-->
21+
<!-- Instead of PSR12.Operators.OperatorSpacing -->
2222
<rule ref="Squiz.WhiteSpace.OperatorSpacing">
2323
<properties>
2424
<property name="ignoreNewlines" value="true"/>
2525
</properties>
2626
</rule>
27-
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
2827

29-
<!-- Change warning to error -->
30-
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
31-
<type>error</type>
28+
<!-- Force control structures indentation with 4 spaces -->
29+
<rule ref="Generic.WhiteSpace.ScopeIndent">
30+
<properties>
31+
<!-- turned off for both comment and phpDoc by PSR2 -> turning back on for phpDoc -->
32+
<property name="ignoreIndentationTokens" type="array">
33+
<element value="T_COMMENT"/>
34+
</property>
35+
</properties>
3236
</rule>
3337

34-
<!-- Override SuperfluousWhitespace to not ignore blank lines -->
38+
<!-- Forbid superfluous whitespaces -->
3539
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
3640
<properties>
41+
<!-- turned on by PSR2 -> turning back off -->
3742
<property name="ignoreBlankLines" value="false"/>
3843
</properties>
3944
</rule>
4045

41-
<!-- Override ScopeIndent to check phpDoc comments indent-->
42-
<rule ref="Generic.WhiteSpace.ScopeIndent">
43-
<properties>
44-
<property name="ignoreIndentationTokens" type="array">
45-
<element value="T_COMMENT"/>
46-
</property>
47-
</properties>
46+
<!-- Disallow else if in favor of elseif -->
47+
<rule ref="PSR2.ControlStructures.ElseIfDeclaration.NotAllowed">
48+
<!-- change warning to error -->
49+
<type>error</type>
50+
</rule>
51+
52+
<!-- **************** -->
53+
<!-- *** CUSTOM *** -->
54+
<!-- **************** -->
55+
56+
<rule ref="SymfonyCustom.Commenting.FunctionComment">
57+
<exclude name="SymfonyCustom.Commenting.FunctionComment.MissingParamComment"/>
4858
</rule>
4959

5060
<!-- ************** -->
5161
<!-- *** MORE *** -->
5262
<!-- ************** -->
5363

54-
<!-- Whitespace -->
64+
<!-- Forbid `array(...)` -->
65+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
66+
<!-- Forbid duplicate classes -->
67+
<rule ref="Generic.Classes.DuplicateClassName"/>
68+
<!-- Forbid assignment in condition -->
69+
<rule ref="Generic.CodeAnalysis.AssignmentInCondition">
70+
<type>error</type>
71+
</rule>
72+
<!-- Forbid superfluous semi-colon -->
73+
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement">
74+
<type>error</type>
75+
</rule>
76+
<!-- Forbid empty statements -->
77+
<rule ref="Generic.CodeAnalysis.EmptyStatement">
78+
<!-- But allow empty catch -->
79+
<exclude name="Generic.CodeAnalysis.EmptyStatement.DetectedCatch"/>
80+
</rule>
81+
<!-- Forbid final methods in final classes -->
82+
<rule ref="Generic.CodeAnalysis.UnnecessaryFinalModifier"/>
83+
<!-- Forbid useless empty method overrides -->
84+
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
85+
<!-- Forbid inline HTML in PHP code -->
86+
<rule ref="Generic.Files.InlineHTML"/>
87+
<!-- Force whitespace after a type cast -->
5588
<rule ref="Generic.Formatting.SpaceAfterCast"/>
89+
<!-- Forbid whitespace after `!` -->
5690
<rule ref="Generic.Formatting.SpaceAfterNot">
5791
<properties>
5892
<property name="spacing" value="0" />
5993
</properties>
6094
</rule>
61-
<rule ref="Generic.WhiteSpace.SpreadOperatorSpacingAfter"/>
62-
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
63-
<rule ref="Squiz.Strings.ConcatenationSpacing">
64-
<properties>
65-
<property name="ignoreNewlines" value="true" />
66-
</properties>
67-
</rule>
68-
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
69-
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
70-
<properties>
71-
<property name="spacingBeforeFirst" value="0"/>
72-
<property name="spacing" value="1"/>
73-
<property name="spacingAfterLast" value="0"/>
74-
</properties>
75-
</rule>
76-
<rule ref="Squiz.WhiteSpace.MemberVarSpacing">
95+
<!-- Forbid PHP 4 constructors -->
96+
<rule ref="Generic.NamingConventions.ConstructorName"/>
97+
<!-- Forbid any content before opening tag -->
98+
<rule ref="Generic.PHP.CharacterBeforePHPOpeningTag"/>
99+
<!-- Forbid deprecated functions -->
100+
<rule ref="Generic.PHP.DeprecatedFunctions"/>
101+
<!-- Forbid shorthand PHP open tags `<?=` -->
102+
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
103+
<!-- Forbid alias functions, i.e. `sizeof()`, `delete()` -->
104+
<rule ref="Generic.PHP.ForbiddenFunctions">
77105
<properties>
78-
<property name="spacingBeforeFirst" value="0"/>
106+
<property name="forbiddenFunctions" type="array">
107+
<element key="chop" value="rtrim"/>
108+
<element key="close" value="closedir"/>
109+
<element key="compact" value="null"/>
110+
<element key="delete" value="unset"/>
111+
<element key="doubleval" value="floatval"/>
112+
<element key="extract" value="null"/>
113+
<element key="fputs" value="fwrite"/>
114+
<element key="ini_alter" value="ini_set"/>
115+
<element key="is_double" value="is_float"/>
116+
<element key="is_integer" value="is_int"/>
117+
<element key="is_long" value="is_int"/>
118+
<element key="is_null" value="null"/>
119+
<element key="is_real" value="is_float"/>
120+
<element key="is_writeable" value="is_writable"/>
121+
<element key="join" value="implode"/>
122+
<element key="key_exists" value="array_key_exists"/>
123+
<element key="pos" value="current"/>
124+
<element key="settype" value="null"/>
125+
<element key="show_source" value="highlight_file"/>
126+
<element key="sizeof" value="count"/>
127+
<element key="strchr" value="strstr"/>
128+
</property>
79129
</properties>
80130
</rule>
81-
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
131+
<!-- Forbid useless inline string concatenation -->
132+
<rule ref="Generic.Strings.UnnecessaryStringConcat">
133+
<!-- But multiline is useful for readability -->
82134
<properties>
83-
<property name="ignoreNewlines" value="true"/>
135+
<property name="allowMultiline" value="true"/>
84136
</properties>
85137
</rule>
86-
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
87-
88-
<!-- Disallow -->
89-
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
90-
<rule ref="Generic.CodeAnalysis.AssignmentInCondition">
91-
<type>error</type>
92-
</rule>
93-
<rule ref="Generic.CodeAnalysis.EmptyPHPStatement">
94-
<type>error</type>
95-
</rule>
96-
<rule ref="Generic.CodeAnalysis.EmptyStatement"/>
138+
<!-- Forbid backtick operator -->
97139
<rule ref="Generic.PHP.BacktickOperator"/>
98-
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
99-
<rule ref="Generic.PHP.ForbiddenFunctions"/>
100-
<rule ref="PEAR.Commenting.InlineComment"/>
101-
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
102-
<rule ref="Squiz.PHP.DiscouragedFunctions"/>
103-
<rule ref="Squiz.PHP.Eval"/>
104-
<rule ref="Squiz.PHP.NonExecutableCode">
105-
<type>error</type>
106-
</rule>
107-
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
108-
109-
<!-- Others -->
110-
<rule ref="Generic.Strings.UnnecessaryStringConcat">
140+
<!-- Force PHP 7 param and return types to be lowercased -->
141+
<rule ref="Generic.PHP.LowerCaseType"/>
142+
<!-- Forbid `php_sapi_name()` function -->
143+
<rule ref="Generic.PHP.SAPIUsage"/>
144+
<!-- Require there be no space between increment/decrement operator and its operand -->
145+
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
146+
<!-- Override ScopeIndent to check phpDoc comments indent-->
147+
<rule ref="Generic.WhiteSpace.ScopeIndent">
111148
<properties>
112-
<property name="allowMultiline" value="true"/>
149+
<property name="ignoreIndentationTokens" type="array">
150+
<element value="T_COMMENT"/>
151+
</property>
113152
</properties>
114153
</rule>
154+
<!-- Forbid space after the `...` operator -->
155+
<rule ref="Generic.WhiteSpace.SpreadOperatorSpacingAfter"/>
156+
<!-- Forbid comments starting with # -->
157+
<rule ref="PEAR.Commenting.InlineComment"/>
158+
<!-- Forbid spaces around square brackets -->
159+
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
160+
<!-- Forbid class being in a file with different name -->
115161
<rule ref="Squiz.Classes.ClassFileName"/>
162+
<!-- Force `self::` for self-reference, force lower-case self, forbid spaces around `::` -->
163+
<rule ref="Squiz.Classes.SelfMemberReference"/>
164+
<!-- Force phpDoc alignment -->
116165
<rule ref="Squiz.Commenting.DocCommentAlignment">
166+
<!-- Allow extra spaces after star, i.e. for indented annotations -->
117167
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceAfterStar"/>
118168
</rule>
169+
<!-- Require an explanation inside empty catch -->
119170
<rule ref="Squiz.Commenting.EmptyCatchComment"/>
171+
<!-- Force camelCase variables -->
120172
<rule ref="Squiz.NamingConventions.ValidVariableName">
121173
<exclude name="Squiz.NamingConventions.ValidVariableName.PrivateNoUnderscore"/>
122174
<exclude name="Squiz.NamingConventions.ValidVariableName.ContainsNumbers"/>
123175
</rule>
176+
<!-- Forbid `AND` and `OR`, require `&&` and `||` -->
177+
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
178+
<!-- Forbid functions inside functions -->
179+
<rule ref="Squiz.PHP.InnerFunctions"/>
180+
<!-- Require PHP function calls in lowercase -->
124181
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
182+
<!-- Forbid multiple assignments -->
183+
<rule ref="Squiz.PHP.DisallowMultipleAssignments"/>
184+
<!-- Forbid dead code -->
185+
<rule ref="Squiz.PHP.NonExecutableCode">
186+
<type>error</type>
187+
</rule>
188+
<!-- Forbid `$this` inside static function -->
189+
<rule ref="Squiz.Scope.StaticThisUsage"/>
190+
<!-- Require class function to have scope modifiers -->
125191
<rule ref="Squiz.Scope.MemberVarScope"/>
192+
<!-- Forbid whitespace before and after concatenation -->
193+
<rule ref="Squiz.Strings.ConcatenationSpacing">
194+
<properties>
195+
<property name="ignoreNewlines" value="true"/>
196+
</properties>
197+
</rule>
198+
<!-- Forbid strings in `"` unless necessary -->
126199
<rule ref="Squiz.Strings.DoubleQuoteUsage">
127200
<exclude name="Squiz.Strings.DoubleQuoteUsage.ContainsVar"/>
128201
</rule>
202+
<!-- Forbid braces around string in `echo` -->
129203
<rule ref="Squiz.Strings.EchoedStrings"/>
130-
131-
<!-- Custom -->
132-
<rule ref="SymfonyCustom.Commenting.FunctionComment">
133-
<exclude name="SymfonyCustom.Commenting.FunctionComment.MissingParamComment"/>
204+
<!-- Forbid spaces in type casts -->
205+
<rule ref="Squiz.WhiteSpace.CastSpacing"/>
206+
<!-- Forbid blank line after function opening brace -->
207+
<rule ref="Squiz.WhiteSpace.FunctionOpeningBraceSpace"/>
208+
<!-- Require 1 line before and after function, except at the top and bottom -->
209+
<rule ref="Squiz.WhiteSpace.FunctionSpacing">
210+
<properties>
211+
<property name="spacingBeforeFirst" value="0"/>
212+
<property name="spacing" value="1"/>
213+
<property name="spacingAfterLast" value="0"/>
214+
</properties>
215+
</rule>
216+
<!-- Require space after language constructs -->
217+
<rule ref="Squiz.WhiteSpace.LanguageConstructSpacing"/>
218+
<!-- Require space around logical operators -->
219+
<rule ref="Squiz.WhiteSpace.LogicalOperatorSpacing"/>
220+
<!-- Require 1 line before and after class properties, except at the top -->
221+
<rule ref="Squiz.WhiteSpace.MemberVarSpacing">
222+
<properties>
223+
<property name="spacingBeforeFirst" value="0"/>
224+
</properties>
134225
</rule>
226+
<!-- Forbid spaces around `->` operator -->
227+
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing">
228+
<properties>
229+
<property name="ignoreNewlines" value="true"/>
230+
</properties>
231+
</rule>
232+
<!-- Forbid spaces before semicolon `;` -->
233+
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
135234
</ruleset>

0 commit comments

Comments
 (0)