Skip to content

Commit cd90d67

Browse files
committed
Add new sniffs from new Slevomat rules
1 parent 4f4fcc6 commit cd90d67

File tree

5 files changed

+43
-26
lines changed

5 files changed

+43
-26
lines changed

README.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# PHP CodeSniffer - Custom standard ruleset
22

3+
[![PHP from Packagist](https://img.shields.io/packagist/php-v/arxeiss/coding-standards)](https://packagist.org/packages/arxeiss/coding-standards)
4+
[![Packagist Version](https://img.shields.io/packagist/v/arxeiss/coding-standards)](https://packagist.org/packages/arxeiss/coding-standards)
5+
36
Custom ruleset for [PHP CodeSniffer](https://github.com/squizlabs/PHP_CodeSniffer) with [Slevomat sniffs](https://github.com/slevomat/coding-standard). Ruleset is based on **PSR2 + PSR12** with additional rules, more detailed list is below. Ruleset is possible to use with **space indentation** and also **tabs indentation**.
47

58
## Installation and running
@@ -127,11 +130,17 @@ There is no really good documentation for sniffs. I wrote one sentence explanati
127130
- PSR2.Namespaces.NamespaceDeclaration
128131
- PSR2.Namespaces.UseDeclaration
129132

130-
### SlevomatCodingStandard (36 sniffs)
133+
### SlevomatCodingStandard (44 sniffs)
131134
- SlevomatCodingStandard.Arrays.TrailingArrayComma
135+
- SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement
136+
- SlevomatCodingStandard.Classes.ConstantSpacing
132137
- SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants
133138
- SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces
134139
- SlevomatCodingStandard.Classes.ModernClassNameReference
140+
- SlevomatCodingStandard.Classes.ParentCallSpacing
141+
- SlevomatCodingStandard.Classes.PropertySpacing
142+
- SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature
143+
- SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature
135144
- SlevomatCodingStandard.Classes.TraitUseSpacing
136145
- SlevomatCodingStandard.Classes.UselessLateStaticBinding
137146
- SlevomatCodingStandard.Commenting.EmptyComment
@@ -143,6 +152,7 @@ There is no really good documentation for sniffs. I wrote one sentence explanati
143152
- SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator
144153
- SlevomatCodingStandard.Exceptions.DeadCatch
145154
- SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly
155+
- SlevomatCodingStandard.Functions.DisallowEmptyFunction
146156
- SlevomatCodingStandard.Functions.StaticClosure
147157
- SlevomatCodingStandard.Functions.TrailingCommaInCall
148158
- SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure
@@ -160,6 +170,7 @@ There is no really good documentation for sniffs. I wrote one sentence explanati
160170
- SlevomatCodingStandard.Namespaces.UseSpacing
161171
- SlevomatCodingStandard.Namespaces.UselessAlias
162172
- SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator
173+
- SlevomatCodingStandard.Operators.NegationOperatorSpacing
163174
- SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking
164175
- SlevomatCodingStandard.PHP.ShortList
165176
- SlevomatCodingStandard.PHP.TypeCast
@@ -195,7 +206,6 @@ There is no really good documentation for sniffs. I wrote one sentence explanati
195206
- Squiz.WhiteSpace.CastSpacing
196207
- Squiz.WhiteSpace.ControlStructureSpacing
197208
- Squiz.WhiteSpace.FunctionSpacing
198-
- Squiz.WhiteSpace.MemberVarSpacing
199209
- Squiz.WhiteSpace.ObjectOperatorSpacing
200210
- Squiz.WhiteSpace.ScopeClosingBrace
201211
- Squiz.WhiteSpace.ScopeKeywordSpacing

Rules/Parts/phpcs-slevomat.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,31 @@
44
<config name="installed_paths" value="../../slevomat/coding-standard"/>
55

66
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/> <!-- Multiline array must have trailing comma -->
7+
<rule ref="SlevomatCodingStandard.Arrays.MultiLineArrayEndBracketPlacement"/>
8+
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing"> <!-- Proper spacing for constants with and without docblock -->
9+
<properties>
10+
<property name="maxLinesCountBeforeWithoutComment" value="0"/>
11+
</properties>
12+
</rule>
713
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/> <!-- Disable static:: for constants -->
8-
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/> <!-- Replace old get_called_class() etc via modern constructs -->
9-
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/> <!-- Replace static:: into self:: when class/method is final -->
1014
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces"> <!-- No empty lines in the start and end of class -->
1115
<properties>
1216
<property name="linesCountAfterOpeningBrace" value="0"/>
1317
<property name="linesCountBeforeClosingBrace" value="0"/>
1418
</properties>
1519
</rule>
20+
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/> <!-- Replace old get_called_class() etc via modern constructs -->
21+
<rule ref="SlevomatCodingStandard.Classes.ParentCallSpacing"/> <!-- Enforce empty lines around parent method call -->
22+
<rule ref="SlevomatCodingStandard.Classes.PropertySpacing"/> <!-- Proper spacing for property with and without docblock -->
23+
<rule ref="SlevomatCodingStandard.Classes.RequireMultiLineMethodSignature"/> <!-- Method signature should be multiline if exceed 120 chars -->
24+
<rule ref="SlevomatCodingStandard.Classes.RequireSingleLineMethodSignature"/> <!-- Method signature should be single line if does not exceed 120 chars -->
1625
<rule ref="SlevomatCodingStandard.Classes.TraitUseSpacing"> <!-- Spacing around use traits -->
1726
<properties>
1827
<property name="linesCountBeforeFirstUse" value="0"/>
1928
<property name="linesCountAfterLastUseWhenLastInClass" value="0"/>
2029
</properties>
2130
</rule>
31+
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/> <!-- Replace static:: into self:: when class/method is final -->
2232
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/> <!-- Disable empty comments -->
2333
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/> <!-- Check valid inline @var doc -->
2434
<rule ref="SlevomatCodingStandard.Commenting.RequireOneLinePropertyDocComment"/> <!-- Use single line comment for property -->
@@ -35,6 +45,7 @@
3545
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/> <!-- Use null coalesce ?? instead of ternary when possible -->
3646
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/> <!-- Check unreachable catch blocks -->
3747
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/> <!-- \Exception should be \Throwable -->
48+
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/> <!-- Empty function must have a comment why is empty -->
3849
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/> <!-- Use static closure if not using $this -->
3950
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/> <!-- PHP 7.3+ add trailing comma in multiline function call -->
4051
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/> <!-- Check unused variable in use() for closure -->
@@ -64,6 +75,7 @@
6475
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/> <!-- Disable useless namespace alias -->
6576
<rule ref="SlevomatCodingStandard.Numbers.DisallowNumericLiteralSeparator"/> <!-- Disable write number with _ between thousands etc -->
6677
<rule ref="SlevomatCodingStandard.Namespaces.UseSpacing"/> <!-- Empty lines around use statements -->
78+
<rule ref="SlevomatCodingStandard.Operators.NegationOperatorSpacing"/> <!-- No spaces after - (minus) when is meant as negative number -->
6779
<rule ref="SlevomatCodingStandard.PHP.OptimizedFunctionsWithoutUnpacking"/> <!-- In listed function ... must not be used -->
6880
<rule ref="SlevomatCodingStandard.PHP.ShortList"/> <!-- Disable list() use [] -->
6981
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/> <!-- Enforces using shorthand cast operators integer -> int -->

Rules/Parts/phpcs-squiz.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,6 @@
5252
<property name="spacingAfterLast" value="0"/>
5353
</properties>
5454
</rule>
55-
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"> <!-- Spaces between Class members -->
56-
<properties>
57-
<property name="spacingBeforeFirst" value="0"></property>
58-
</properties>
59-
</rule>
6055
<rule ref="Squiz.WhiteSpace.ObjectOperatorSpacing"> <!-- No spaces around object operator -> and :: -->
6156
<properties>
6257
<property name="ignoreNewlines" value="true"/>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "arxeiss/coding-standards",
33
"description": "Custom PHP CodeSniffer ruleset",
4-
"license": "MIT",
4+
"license": "Apache-2.0",
55
"type": "phpcodesniffer-standard",
66
"authors": [
77
{

composer.lock

Lines changed: 16 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)