Skip to content

Commit 41481aa

Browse files
committed
Add many new rules
1 parent 687baee commit 41481aa

File tree

2 files changed

+236
-8
lines changed

2 files changed

+236
-8
lines changed

CHANGELOG.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## 1.2.0 - unreleased
1+
## 2.1.0 - unreleased
22

33
ADDED:
44

@@ -8,6 +8,43 @@ REMOVED:
88

99
FIXED:
1010

11+
## 2.0.0 - 2019-08-22
12+
13+
ADDED:
14+
15+
- Check to forbid duplicate class names
16+
- Check to forbid inline HTML in PHP code
17+
- Check to forbid alias functions
18+
- Check to forbid Late Static Binding of constants
19+
- Check to forbid dead code
20+
- Check to specific order of phpDoc annotations with empty newline between groups
21+
- Check to forbid useless comments
22+
- Check to require comments with single line written as one-liners
23+
- Check to forbid assignments in conditions
24+
- Check to require consistent spacing for control structures
25+
- Check to forbid usage of conditions when a simple return can be used
26+
- Check to forbid usage of boolean-only ternary operator usage
27+
- Check to forbid useless unreachable catch blocks
28+
- Check to require closures not referencing $this be static
29+
- Check to require newlines around namespace declaration
30+
- Check to require only one namespace declaration in a file
31+
- Check to forbid useless alias for classes, constants and functions
32+
- Check to require no spacing after spread operator
33+
- Check to forbid argument unpacking for functions specialized by PHP VM
34+
- Check to forbid useless semicolon
35+
- Check to require types to be written as natively if possible
36+
- Check to forbid useless @var for constants
37+
- Check to forbid duplicated variables assignments
38+
- Check to forbid useless variables
39+
- Check to force rules for function phpDoc
40+
- Check to forbid global functions
41+
- Check to forbid functions inside functions
42+
- Check to forbid superfluous whitespaces
43+
44+
CHANGED:
45+
46+
- Increased minimum PHP version requirement to 7.4
47+
1148
## 1.1.2 - 2019-02-07
1249

1350
REMOVED:

src/WoohooLabs/ruleset.xml

Lines changed: 198 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
<!-- Forbid `array(...)` -->
1212
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
1313

14+
<!-- Forbid duplicate classes -->
15+
<rule ref="Generic.Classes.DuplicateClassName"/>
16+
1417
<!-- Forbid empty statements -->
1518
<rule ref="Generic.CodeAnalysis.EmptyStatement">
1619
<!-- But allow empty catch -->
@@ -23,6 +26,9 @@
2326
<!-- Forbid useless empty method overrides -->
2427
<rule ref="Generic.CodeAnalysis.UselessOverridingMethod"/>
2528

29+
<!-- Forbid inline HTML in PHP code -->
30+
<rule ref="Generic.Files.InlineHTML"/>
31+
2632
<rule ref="Generic.Files.LineLength">
2733
<properties>
2834
<property name="lineLimit" value="160"/>
@@ -31,7 +37,11 @@
3137
</rule>
3238

3339
<!-- Force whitespace after a type cast -->
34-
<rule ref="Generic.Formatting.SpaceAfterCast"/>
40+
<rule ref="Generic.Formatting.SpaceAfterCast">
41+
<properties>
42+
<property name="spacing" value="1"/>
43+
</properties>
44+
</rule>
3545

3646
<!-- Forbid PHP 4 constructors -->
3747
<rule ref="Generic.NamingConventions.ConstructorName"/>
@@ -42,6 +52,35 @@
4252
<!-- Forbid deprecated functions -->
4353
<rule ref="Generic.PHP.DeprecatedFunctions"/>
4454

55+
<!-- Forbid alias functions, i.e. `sizeof()`, `delete()` -->
56+
<rule ref="Generic.PHP.ForbiddenFunctions">
57+
<properties>
58+
<property name="forbiddenFunctions" type="array">
59+
<element key="chop" value="rtrim"/>
60+
<element key="close" value="closedir"/>
61+
<element key="compact" value="null"/>
62+
<element key="delete" value="unset"/>
63+
<element key="doubleval" value="floatval"/>
64+
<element key="extract" value="null"/>
65+
<element key="fputs" value="fwrite"/>
66+
<element key="ini_alter" value="ini_set"/>
67+
<element key="is_double" value="is_float"/>
68+
<element key="is_integer" value="is_int"/>
69+
<element key="is_long" value="is_int"/>
70+
<element key="is_null" value="null"/>
71+
<element key="is_real" value="is_float"/>
72+
<element key="is_writeable" value="is_writable"/>
73+
<element key="join" value="implode"/>
74+
<element key="key_exists" value="array_key_exists"/>
75+
<element key="pos" value="current"/>
76+
<element key="settype" value="null"/>
77+
<element key="show_source" value="highlight_file"/>
78+
<element key="sizeof" value="count"/>
79+
<element key="strchr" value="strstr"/>
80+
</property>
81+
</properties>
82+
</rule>
83+
4584
<!-- Forbid backtick operator -->
4685
<rule ref="Generic.PHP.BacktickOperator"/>
4786

@@ -75,13 +114,27 @@
75114
</properties>
76115
</rule>
77116

117+
<!-- Forbid LSB for constants (static::FOO) -->
118+
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
119+
120+
<!-- Forbid empty lines around type declarations -->
121+
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
122+
<properties>
123+
<property name="linesCountAfterOpeningBrace" value="0"/>
124+
<property name="linesCountBeforeClosingBrace" value="0"/>
125+
</properties>
126+
</rule>
127+
78128
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
79129
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
80130

81131
<!-- Forbid uses of multiple traits separated by comma -->
82132
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
83133

84-
<!-- Disabling this rule
134+
<!-- Forbid dead code -->
135+
<rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements"/>
136+
137+
<!-- Require specific order of phpDoc annotations with empty newline between specific groups -->
85138
<rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
86139
<properties>
87140
<property name="linesCountBeforeFirstContent" value="0"/>
@@ -98,13 +151,14 @@
98151
@see,
99152
@uses,
100153
"/>
101-
<element value="@param"/>
102-
<element value="@return"/>
103-
<element value="@throws"/>
154+
<element value="
155+
@param,
156+
@return,
157+
@throws,
158+
"/>
104159
</property>
105160
</properties>
106161
</rule>
107-
-->
108162

109163
<!-- Forbid useless annotations - Git and LICENCE file provide more accurate information -->
110164
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenAnnotations">
@@ -127,9 +181,37 @@
127181
<!-- Forbid empty comments -->
128182
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
129183

184+
<!-- Forbid useless comments -->
185+
<rule ref="SlevomatCodingStandard.Commenting.ForbiddenComments">
186+
<properties>
187+
<property name="forbiddenCommentPatterns" type="array">
188+
<element value="~^(?:(?!private|protected|static)\S+ )?(?:con|de)structor\.\z~i"/>
189+
<element value="~^Created by .+\.\z~i"/>
190+
<element value="~^(User|Date|Time): \S+\z~i"/>
191+
<element value="~^\S+ [gs]etter\.\z~i"/>
192+
<element value="~^Class \S+\z~i"/>
193+
</property>
194+
</properties>
195+
</rule>
196+
130197
<!-- report invalid format of inline phpDocs with @var -->
131198
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
132199

200+
<!-- Require comments with single line written as one-liners -->
201+
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/>
202+
203+
<!-- Forbid assignments in conditions -->
204+
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
205+
206+
<!-- Require consistent spacing for control structures -->
207+
<rule ref="SlevomatCodingStandard.ControlStructures.ControlStructureSpacing">
208+
<properties>
209+
<property name="tokensToCheck" type="array">
210+
<element value="T_RETURN" />
211+
</property>
212+
</properties>
213+
</rule>
214+
133215
<!-- Forbid fancy yoda conditions -->
134216
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
135217

@@ -142,9 +224,25 @@
142224
<!-- Require usage of null coalesce operator when possible -->
143225
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
144226

227+
<!-- Forbid usage of conditions when a simple return can be used -->
228+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
229+
230+
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->
231+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
232+
233+
<!-- Forbid useless unreachable catch blocks -->
234+
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
235+
145236
<!-- Require using Throwable instead of Exception -->
146237
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/>
147238

239+
<!-- Require closures not referencing $this be static -->
240+
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/>
241+
242+
<!-- Require trailing comma in multiline calls
243+
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/>
244+
-->
245+
148246
<!-- Forbid unused variables passed to closures via `use` -->
149247
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
150248

@@ -157,6 +255,9 @@
157255
<!-- Forbid multiple use statements on same line -->
158256
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
159257

258+
<!-- Require newlines around namespace declaration -->
259+
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
260+
160261
<!-- Forbid using absolute class name references (except global ones) -->
161262
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
162263
<properties>
@@ -172,6 +273,9 @@
172273
</properties>
173274
</rule>
174275

276+
<!-- Require only one namespace declaration in a file -->
277+
<rule ref="SlevomatCodingStandard.Namespaces.RequireOneNamespaceInFile"/>
278+
175279
<!-- Forbid unused use statements -->
176280
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
177281
<properties>
@@ -194,12 +298,21 @@
194298
</properties>
195299
</rule>
196300

301+
<!-- Forbid useless alias for classes, constants and functions -->
302+
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
303+
197304
<!-- Forbid weak comparisons -->
198305
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
199306

200-
<!-- Forbid whitespace after the spread operator -->
307+
<!-- Require the usage of assignment operators, eg `+=`, `.=` when possible -->
308+
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
309+
310+
<!-- Require no spacing after spread operator -->
201311
<rule ref="SlevomatCodingStandard.Operators.SpreadOperatorSpacing"/>
202312

313+
<!-- forbid argument unpacking for functions specialized by PHP VM -->
314+
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/>
315+
203316
<!-- Forbid `list(...)` syntax -->
204317
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
205318

@@ -218,6 +331,9 @@
218331
<!-- Forbid useless parentheses -->
219332
<rule ref="SlevomatCodingStandard.PHP.UselessParentheses"/>
220333

334+
<!-- Forbid useless semicolon `;` -->
335+
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
336+
221337
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
222338
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
223339

@@ -230,6 +346,25 @@
230346
<!-- Require one space between typehint and variable, require no space between nullability sign and typehint -->
231347
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
232348

349+
<!-- Require types to be written as natively if possible;
350+
require iterable types to specify phpDoc with their content;
351+
forbid useless/duplicated information in phpDoc -->
352+
<rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration">
353+
<properties>
354+
<property name="allAnnotationsAreUseful" value="true"/>
355+
<property name="enableEachParameterAndReturnInspection" value="true"/>
356+
</properties>
357+
</rule>
358+
359+
<!-- Forbid useless @var for constants -->
360+
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
361+
362+
<!-- Forbid duplicated variables assignments -->
363+
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
364+
365+
<!-- Forbid useless variables -->
366+
<rule ref="SlevomatCodingStandard.Variables.UselessVariable"/>
367+
233368
<!-- Forbid spaces around square brackets -->
234369
<rule ref="Squiz.Arrays.ArrayBracketSpacing"/>
235370

@@ -239,12 +374,55 @@
239374
<!-- Force `self::` for self-reference, force lower-case self, forbid spaces around `::` -->
240375
<rule ref="Squiz.Classes.SelfMemberReference"/>
241376

377+
<!-- Force rules for function phpDoc -->
378+
<rule ref="Squiz.Commenting.FunctionComment">
379+
<!-- Allow `@throws` without description -->
380+
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
381+
<!-- Does not work properly with PHP 7 / short-named types -->
382+
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
383+
<!-- Does not support collections, i.e. `string[]` -->
384+
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint"/>
385+
<!-- Forces incorrect types -->
386+
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturn"/>
387+
<!-- Breaks with compound return types, i.e. `string|null` -->
388+
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturnNotVoid"/>
389+
<!-- Breaks when all params are not documented -->
390+
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
391+
<!-- Doc comment is not required for every method -->
392+
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
393+
<!-- Do not require comments for `@param` -->
394+
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/>
395+
<!-- Do not require `@param` for all parameters -->
396+
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
397+
<!-- Do not require `@return` for void methods -->
398+
<exclude name="Squiz.Commenting.FunctionComment.MissingReturn"/>
399+
<!-- Comments don't have to be sentences -->
400+
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
401+
<!-- Comments don't have to be sentences -->
402+
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
403+
<!-- Breaks when all params are not documented -->
404+
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
405+
<!-- Doesn't respect inheritance -->
406+
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
407+
<!-- `@throws` lines can often be read as a sentence,
408+
i.e. `@throws RuntimeException if the file could not be written.` -->
409+
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNotCapital"/>
410+
<!-- Doesn't work with self as typehint -->
411+
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
412+
</rule>
413+
414+
<!-- Forbid global functions -->
415+
<rule ref="Squiz.Functions.GlobalFunction"/>
416+
242417
<!-- Forbid `AND` and `OR`, require `&&` and `||` -->
243418
<rule ref="Squiz.Operators.ValidLogicalOperators"/>
244419

245420
<!-- Forbid `global` -->
246421
<rule ref="Squiz.PHP.GlobalKeyword"/>
247422

423+
<!-- Forbid functions inside functions -->
424+
<rule ref="Squiz.PHP.InnerFunctions"/>
425+
248426
<!-- Require PHP function calls in lowercase -->
249427
<rule ref="Squiz.PHP.LowercasePHPFunctions"/>
250428

@@ -289,4 +467,17 @@
289467

290468
<!-- Forbid spaces before semicolon `;` -->
291469
<rule ref="Squiz.WhiteSpace.SemicolonSpacing"/>
470+
471+
<!-- Forbid superfluous whitespaces -->
472+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
473+
<properties>
474+
<!-- turned on by PSR2 -> turning back off -->
475+
<property name="ignoreBlankLines" value="false"/>
476+
</properties>
477+
</rule>
478+
479+
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines">
480+
<!-- turned off by PSR2 -> turning back on -->
481+
<severity>5</severity>
482+
</rule>
292483
</ruleset>

0 commit comments

Comments
 (0)