Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.

Commit e8f39b0

Browse files
committed
Merge pull request #10 from webimpress/feature/additional-sniffs
Additional sniffs and tests
2 parents 1688342 + 31e54f1 commit e8f39b0

36 files changed

+537
-91
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"php": "^7.1",
2121
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
2222
"slevomat/coding-standard": "^4.8.0",
23-
"squizlabs/php_codesniffer": "^3.3.2",
23+
"squizlabs/php_codesniffer": "^3.4.0",
2424
"webimpress/coding-standard": "dev-master"
2525
},
2626
"extra": {

src/ZendCodingStandard/ruleset.xml

Lines changed: 97 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@
1515
<exclude name="PSR2.Methods.FunctionClosingBrace.SpacingBeforeClose"/>
1616
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingAfterOpen"/>
1717
<exclude name="Squiz.WhiteSpace.ControlStructureSpacing.SpacingBeforeClose"/>
18+
<!-- Replaced by WebimpressCodingStandard.WhiteSpace.CommaSpacing -->
19+
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpaceBeforeComma"/>
20+
<exclude name="Squiz.Functions.FunctionDeclarationArgumentSpacing.NoSpaceBeforeArg"/>
21+
<!-- Replaced by WebimpressCodingStandard.WhiteSpace.ScopeIndent -->
22+
<exclude name="Generic.WhiteSpace.ScopeIndent"/>
23+
<exclude name="PSR2.Methods.FunctionCallSignature.Indent"/>
24+
<exclude name="PSR2.Methods.FunctionCallSignature.OpeningIndent"/>
25+
<exclude name="Squiz.Functions.MultiLineFunctionDeclaration.Indent"/>
26+
<exclude name="Squiz.WhiteSpace.ScopeClosingBrace.Indent"/>
1827
</rule>
1928

2029
<!-- Force array element indentation with 4 spaces -->
@@ -34,10 +43,14 @@
3443
<!-- Forbid blank line after opening braces and before closing braces -->
3544
<rule ref="WebimpressCodingStandard.WhiteSpace.BraceBlankLine"/>
3645

46+
<!-- Forbid FQN for classes/traits/interfaces/constants/functions -->
47+
<rule ref="WebimpressCodingStandard.PHP.DisallowFqn"/>
3748
<!-- Import internal constants -->
3849
<rule ref="WebimpressCodingStandard.PHP.ImportInternalConstant"/>
3950
<!-- Import internal functions -->
4051
<rule ref="WebimpressCodingStandard.PHP.ImportInternalFunction"/>
52+
<!-- Format anonymous class declaration -->
53+
<rule ref="WebimpressCodingStandard.Classes.AnonymousClassDeclaration"/>
4154
<!-- Forbid null values for class properties -->
4255
<rule ref="WebimpressCodingStandard.Classes.NoNullValues"/>
4356
<!-- Comments at the end of the line, with at least single space -->
@@ -46,21 +59,70 @@
4659
<!-- Requires one space after namespace keyword -->
4760
<rule ref="WebimpressCodingStandard.WhiteSpace.Namespace"/>
4861
<!-- Forbid spaces around namespace separator -->
49-
<!-- TODO: Cannot be included because of error in SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly -->
50-
<!--<rule ref="WebimpressCodingStandard.WhiteSpace.NamespaceSeparator"/>-->
62+
<rule ref="WebimpressCodingStandard.WhiteSpace.NamespaceSeparator"/>
5163

5264
<!-- One space after break/continue with argument, remove redundant 1 -->
5365
<rule ref="WebimpressCodingStandard.ControlStructures.BreakAndContinue"/>
5466
<!-- Forbid continue in switch; use break instead -->
5567
<rule ref="WebimpressCodingStandard.ControlStructures.ContinueInSwitch"/>
5668

69+
<!-- Forbid boolean operator at the end of the line -->
70+
<rule ref="WebimpressCodingStandard.Operators.BooleanOperator"/>
71+
<!-- Formatting of ternary operator - content must be after ?/:, not in new line -->
72+
<rule ref="WebimpressCodingStandard.Operators.TernaryOperator"/>
73+
74+
<!-- Abstract class must have Abstract* prefix -->
75+
<rule ref="WebimpressCodingStandard.NamingConventions.AbstractClass"/>
76+
<!-- Exception must have *Exception suffix -->
77+
<rule ref="WebimpressCodingStandard.NamingConventions.Exception"/>
78+
<!-- Interface must have *Interface suffix -->
79+
<rule ref="WebimpressCodingStandard.NamingConventions.Interface"/>
80+
<!-- Trait must have *Traif suffix -->
81+
<rule ref="WebimpressCodingStandard.NamingConventions.Trait"/>
5782
<!-- Require camelCase variable names -->
5883
<rule ref="WebimpressCodingStandard.NamingConventions.ValidVariableName"/>
5984

85+
<!-- Use the correct class name, i.e. DateTime not Datetime, etc -->
86+
<rule ref="WebimpressCodingStandard.PHP.CorrectClassNameCase"/>
87+
88+
<!-- Only one blank line allowed -->
89+
<rule ref="WebimpressCodingStandard.WhiteSpace.BlankLine"/>
90+
91+
<!-- Indents formatting -->
92+
<rule ref="WebimpressCodingStandard.WhiteSpace.ScopeIndent">
93+
<properties>
94+
<property name="alignObjectOperators" value="false"></property>
95+
</properties>
96+
</rule>
97+
6098
<!-- Detects for-loops that can be simplified to a while-loop -->
6199
<rule ref="Generic.CodeAnalysis.ForLoopShouldBeWhileLoop"/>
62100
<!-- Detects unconditional if- and elseif-statements -->
63101
<rule ref="Generic.CodeAnalysis.UnconditionalIfStatement"/>
102+
<!-- Disallow spaces before/after incrementation/decrementation operators -->
103+
<rule ref="Generic.WhiteSpace.IncrementDecrementSpacing"/>
104+
105+
<!-- Forbid inline comments after closing curly bracket, like // end if etc -->
106+
<rule ref="WebimpressCodingStandard.Commenting.NoInlineCommentAfterCurlyClose"/>
107+
<!-- Use correct case of default PHPDocs and PHPUnit tags @var not @VAR etc -->
108+
<rule ref="WebimpressCodingStandard.Commenting.TagCase"/>
109+
<!-- Heredoc/nowdoc tag uppercase without spaces -->
110+
<rule ref="WebimpressCodingStandard.Formatting.Heredoc"/>
111+
112+
<!-- Forbid space after splat operator -->
113+
<rule ref="WebimpressCodingStandard.Formatting.NoSpaceAfterSplat"/>
114+
<!-- Forbid reference operator before new, and formatting of the reference operator -->
115+
<rule ref="WebimpressCodingStandard.Formatting.Reference"/>
116+
<!-- Use ::class instead of class string reference -->
117+
<rule ref="WebimpressCodingStandard.Formatting.StringClassReference"/>
118+
<!-- Single line between methods in class -->
119+
<rule ref="WebimpressCodingStandard.Methods.LineAfter"/>
120+
121+
<!-- Forbid space before comma, require single space after comma -->
122+
<rule ref="WebimpressCodingStandard.WhiteSpace.CommaSpacing"/>
123+
124+
<!-- Forbid concatenation character at the end of the line -->
125+
<rule ref="WebimpressCodingStandard.Strings.NoConcatenationAtTheEnd"/>
64126

65127
<!-- Forbid duplicate classes -->
66128
<rule ref="Generic.Classes.DuplicateClassName"/>
@@ -177,6 +239,10 @@
177239
<element value="@package"/>
178240
<element value="@subpackage"/>
179241
<element value="@version"/>
242+
<element value="@expectedException"/>
243+
<element value="@expectedExceptionCode"/>
244+
<element value="@expectedExceptionMessage"/>
245+
<element value="@expectedExceptionMessageRegExp"/>
180246
</property>
181247
</properties>
182248
</rule>
@@ -201,7 +267,7 @@
201267
<!-- Require language constructs without parentheses -->
202268
<rule ref="SlevomatCodingStandard.ControlStructures.LanguageConstructWithParentheses"/>
203269
<!-- Require new instances with parentheses -->
204-
<rule ref="WebimpressCodingStandard.PHP.InstantiatingParenthesis"/>
270+
<rule ref="PSR12.Classes.ClassInstantiation"/>
205271
<!-- Require usage of null coalesce operator when possible -->
206272
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
207273
<!-- Forbid useless unreachable catch blocks -->
@@ -224,44 +290,28 @@
224290
<rule ref="SlevomatCodingStandard.Namespaces.MultipleUsesPerLine"/>
225291
<!-- Require newlines around namespace declaration -->
226292
<rule ref="SlevomatCodingStandard.Namespaces.NamespaceSpacing"/>
227-
<!-- Forbid using absolute class name references (except global ones) -->
228-
<rule ref="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly">
229-
<properties>
230-
<property name="allowFallbackGlobalConstants" value="false"/>
231-
<property name="allowFallbackGlobalFunctions" value="false"/>
232-
<property name="allowFullyQualifiedGlobalClasses" value="false"/>
233-
<property name="allowFullyQualifiedGlobalConstants" value="false"/>
234-
<property name="allowFullyQualifiedGlobalFunctions" value="false"/>
235-
<property name="allowFullyQualifiedNameForCollidingClasses" value="true"/>
236-
<property name="allowFullyQualifiedNameForCollidingConstants" value="true"/>
237-
<property name="allowFullyQualifiedNameForCollidingFunctions" value="true"/>
238-
<property name="searchAnnotations" value="true"/>
239-
</properties>
240-
</rule>
241-
<!-- Forbid useless alias for classes, constants and functions -->
242-
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
293+
<!-- Forbid useless alias for classes, constants, functions and traits functions -->
294+
<rule ref="WebimpressCodingStandard.Namespaces.RedundantAlias"/>
243295
<!-- Require the usage of assignment operators, eg `+=`, `.=` when possible -->
244296
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
245297
<!-- Forbid `list(...)` syntax, use [...] instead -->
246298
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
247299
<!-- Forbid use of longhand cast operators -->
248300
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
249301
<!-- Require presence of declare(strict_types=1) -->
250-
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
251-
<properties>
252-
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
253-
<property name="spacesCountAroundEqualsSign" value="0"/>
254-
<property name="newlinesCountAfterDeclare" value="2"/>
255-
</properties>
256-
</rule>
302+
<rule ref="WebimpressCodingStandard.Files.DeclareStrictTypes"/>
303+
<!-- Format of strict type declaration -->
304+
<rule ref="WebimpressCodingStandard.PHP.DeclareStrictTypes"/>
257305
<!-- Forbid useless parentheses -->
258-
<rule ref="WebimpressCodingStandard.Formatting.UnnecessaryParentheses"/>
259-
<!-- Forbid useless semicolon `;` -->
260-
<rule ref="SlevomatCodingStandard.PHP.UselessSemicolon"/>
306+
<rule ref="WebimpressCodingStandard.Formatting.RedundantParentheses"/>
307+
<!-- Forbid redundant semicolons -->
308+
<rule ref="WebimpressCodingStandard.PHP.RedundantSemicolon"/>
261309
<!-- Require use of short versions of scalar types (i.e. int instead of integer) -->
262310
<rule ref="SlevomatCodingStandard.TypeHints.LongTypeHints"/>
263311
<!-- Require ? when default value is null -->
264312
<rule ref="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/>
313+
<!-- Disallow space after nullable operator -->
314+
<rule ref="PSR12.Functions.NullableTypeDeclaration"/>
265315
<!-- Require one space between typehint and variable, require no space between nullability sign and typehint -->
266316
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHintSpacing"/>
267317
<!-- Require space around colon in return types -->
@@ -281,40 +331,40 @@
281331
<exclude name="Squiz.Commenting.DocCommentAlignment.SpaceAfterStar"/>
282332
</rule>
283333
<!-- Force rules for function phpDoc -->
284-
<rule ref="Squiz.Commenting.FunctionComment">
334+
<rule ref="PEAR.Commenting.FunctionComment">
285335
<!-- Allow `@throws` without description -->
286-
<exclude name="Squiz.Commenting.FunctionComment.EmptyThrows"/>
336+
<exclude name="PEAR.Commenting.FunctionComment.EmptyThrows"/>
287337
<!-- Does not work properly with PHP 7 / short-named types -->
288-
<exclude name="Squiz.Commenting.FunctionComment.IncorrectParamVarName"/>
338+
<exclude name="PEAR.Commenting.FunctionComment.IncorrectParamVarName"/>
289339
<!-- Does not support collections, i.e. `string[]` -->
290-
<exclude name="Squiz.Commenting.FunctionComment.IncorrectTypeHint"/>
340+
<exclude name="PEAR.Commenting.FunctionComment.IncorrectTypeHint"/>
291341
<!-- Forces incorrect types -->
292-
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturn"/>
342+
<exclude name="PEAR.Commenting.FunctionComment.InvalidReturn"/>
293343
<!-- Breaks with compound return types, i.e. `string|null` -->
294-
<exclude name="Squiz.Commenting.FunctionComment.InvalidReturnNotVoid"/>
344+
<exclude name="PEAR.Commenting.FunctionComment.InvalidReturnNotVoid"/>
295345
<!-- Breaks when all params are not documented -->
296-
<exclude name="Squiz.Commenting.FunctionComment.InvalidTypeHint"/>
346+
<exclude name="PEAR.Commenting.FunctionComment.InvalidTypeHint"/>
297347
<!-- Doc comment is not required for every method -->
298-
<exclude name="Squiz.Commenting.FunctionComment.Missing"/>
348+
<exclude name="PEAR.Commenting.FunctionComment.Missing"/>
299349
<!-- Do not require comments for `@param` -->
300-
<exclude name="Squiz.Commenting.FunctionComment.MissingParamComment"/>
350+
<exclude name="PEAR.Commenting.FunctionComment.MissingParamComment"/>
301351
<!-- Do not require `@param` for all parameters -->
302-
<exclude name="Squiz.Commenting.FunctionComment.MissingParamTag"/>
352+
<exclude name="PEAR.Commenting.FunctionComment.MissingParamTag"/>
303353
<!-- Do not require `@return` for void methods -->
304-
<exclude name="Squiz.Commenting.FunctionComment.MissingReturn"/>
354+
<exclude name="PEAR.Commenting.FunctionComment.MissingReturn"/>
305355
<!-- Comments don't have to be sentences -->
306-
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentFullStop"/>
356+
<exclude name="PEAR.Commenting.FunctionComment.ParamCommentFullStop"/>
307357
<!-- Comments don't have to be sentences -->
308-
<exclude name="Squiz.Commenting.FunctionComment.ParamCommentNotCapital"/>
358+
<exclude name="PEAR.Commenting.FunctionComment.ParamCommentNotCapital"/>
309359
<!-- Breaks when all params are not documented -->
310-
<exclude name="Squiz.Commenting.FunctionComment.ParamNameNoMatch"/>
360+
<exclude name="PEAR.Commenting.FunctionComment.ParamNameNoMatch"/>
311361
<!-- Doesn't respect inheritance -->
312-
<exclude name="Squiz.Commenting.FunctionComment.ScalarTypeHintMissing"/>
362+
<exclude name="PEAR.Commenting.FunctionComment.ScalarTypeHintMissing"/>
313363
<!-- Throws comments can start without a capital and doesn't need a full stop -->
314-
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNoFullStop"/>
315-
<exclude name="Squiz.Commenting.FunctionComment.ThrowsNotCapital"/>
364+
<exclude name="PEAR.Commenting.FunctionComment.ThrowsNoFullStop"/>
365+
<exclude name="PEAR.Commenting.FunctionComment.ThrowsNotCapital"/>
316366
<!-- Doesn't work with self as typehint -->
317-
<exclude name="Squiz.Commenting.FunctionComment.TypeHintMissing"/>
367+
<exclude name="PEAR.Commenting.FunctionComment.TypeHintMissing"/>
318368
</rule>
319369
<!-- Forbid `AND` and `OR`, require `&&` and `||` -->
320370
<rule ref="Squiz.Operators.ValidLogicalOperators"/>

test/expected-report.txt

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,43 @@ PHP CODE SNIFFER REPORT SUMMARY
33
----------------------------------------------------------------------
44
FILE ERRORS WARNINGS
55
----------------------------------------------------------------------
6-
test/fixable/anonymous-classes.php 9 0
7-
test/fixable/array-indentation.php 39 1
8-
test/fixable/class-name-resolution.php 13 0
6+
test/fixable/anonymous-classes.php 11 0
7+
test/fixable/array-indentation.php 47 1
8+
test/fixable/class-name-resolution.php 15 0
99
test/fixable/class-properties.php 6 0
10-
test/fixable/classes-traits-interfaces.php 13 0
10+
test/fixable/classes-traits-interfaces.php 17 1
1111
test/fixable/closures.php 19 0
12-
test/fixable/commenting.php 17 0
13-
test/fixable/concatenation-spacing.php 15 0
14-
test/fixable/control-structures.php 5 0
15-
test/fixable/example-class.php 30 0
16-
test/fixable/extends-and-implements-multiline.php 10 0
12+
test/fixable/commenting.php 26 0
13+
test/fixable/concatenation-spacing.php 21 0
14+
test/fixable/control-structures.php 6 0
15+
test/fixable/example-class.php 29 0
16+
test/fixable/extends-and-implements-multiline.php 13 0
1717
test/fixable/extends-and-implements.php 5 0
18-
test/fixable/forbidden-comments.php 4 0
18+
test/fixable/forbidden-comments.php 6 0
1919
test/fixable/forbidden-functions.php 6 0
20+
test/fixable/heredoc-nowdoc.php 6 0
2021
test/fixable/LowCaseTypes.php 2 0
21-
test/fixable/method-and-function-arguments.php 11 0
22-
test/fixable/method-and-function-calls.php 13 0
23-
test/fixable/namespaces-spacing.php 3 0
22+
test/fixable/method-and-function-arguments.php 16 0
23+
test/fixable/method-and-function-calls.php 15 0
24+
test/fixable/namespaces-spacing.php 7 0
25+
test/fixable/naming.php 12 0
2426
test/fixable/new-with-parentheses.php 19 0
25-
test/fixable/not-spacing.php 14 0
26-
test/fixable/operators.php 9 0
27+
test/fixable/not-spacing.php 33 1
28+
test/fixable/operators.php 17 0
2729
test/fixable/return-type-on-methods.php 17 0
28-
test/fixable/semicolon-spacing.php 3 0
30+
test/fixable/semicolon-spacing.php 5 0
31+
test/fixable/spacing.php 18 1
2932
test/fixable/statement-alignment.php 19 0
3033
test/fixable/test-case.php 4 0
3134
test/fixable/traits-uses.php 9 0
3235
test/fixable/UnusedVariables.php 1 0
33-
test/fixable/useless-semicolon.php 2 0
36+
test/fixable/useless-semicolon.php 8 0
3437
test/fixable/variable-names.php 5 2
3538
test/fixable/visibility-declaration.php 1 0
3639
----------------------------------------------------------------------
37-
A TOTAL OF 323 ERRORS AND 3 WARNINGS WERE FOUND IN 30 FILES
40+
A TOTAL OF 441 ERRORS AND 6 WARNINGS WERE FOUND IN 33 FILES
3841
----------------------------------------------------------------------
39-
PHPCBF CAN FIX 276 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
42+
PHPCBF CAN FIX 377 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4043
----------------------------------------------------------------------
4144

4245

test/fixable/anonymous-classes.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
// Brace on the next line
1313
$instance = new class() extends \Foo implements
1414
\ArrayAccess,
15-
\Countable,
16-
\Serializable
15+
\Countable,
16+
\Serializable
1717
{
1818

1919
// Class content

test/fixable/class-name-resolution.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,11 @@ public function getMethodWithFullyQualifiedName() : string
3737
{
3838
return \get_called_class();
3939
}
40+
41+
public function classNotationInsteadOfString() : string
42+
{
43+
$a = '\PHP_CodeSniffer\Config';
44+
45+
return '\ArrayObject';
46+
}
4047
}

test/fixable/classes-traits-interfaces.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,31 @@
22

33
declare(strict_types=1);
44

5+
namespace FooBar;
6+
7+
use Arrayobject as AO;
8+
59
class Foo
610
{
711

812
public $bar;
913

1014
}
1115

12-
trait Bar
16+
trait BarTrait
1317
{
1418

1519
public $var;
1620

1721
}
1822

19-
interface Baz
23+
interface BazInterface
2024
{
2125

2226
public function big() : int;
2327

2428
}
29+
30+
new \Datetime();
31+
new \arrayobject();
32+
new Ao();

0 commit comments

Comments
 (0)