Skip to content

Commit 30cef7e

Browse files
committed
Add new rules from v7 of Slevomat rules
1 parent 35aee07 commit 30cef7e

File tree

6 files changed

+54
-5
lines changed

6 files changed

+54
-5
lines changed

CHANGELOG.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,28 @@
11
# Changelog
22

3+
## v0.8.x
4+
5+
### v0.8.0
6+
7+
> Requires Slevomat coding standards 7.0 or higher
8+
9+
**Added rules:**
10+
- SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator
11+
- SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch
12+
- SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration
13+
14+
**Added strict rules:**
15+
- SlevomatCodingStandard.TypeHints.UnionTypeHintFormat
16+
17+
**Renamed rules:**
18+
- SlevomatCodingStandard.Functions.TrailingCommaInCall into SlevomatCodingStandard.Functions.**Require**TrailingCommaInCall
19+
320
## v0.7.x
421

22+
### v0.7.1
23+
24+
Added support for PHP 8
25+
526
### v0.7.0
627

728
> Requires Slevomat coding standards 6.4 or higher

Rules/Parts/phpcs-slevomat.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,16 @@
5454
</properties>
5555
</rule>
5656
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/> <!-- Use null coalesce ?? instead of ternary when possible -->
57+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/> <!-- Requires using ?-> operator -->
5758
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/> <!-- Check unreachable catch blocks -->
5859
<rule ref="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/> <!-- \Exception should be \Throwable -->
60+
<rule ref="SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch"/> <!-- Require non-capturing catch when the variable with exception is not used. -->
5961
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/> <!-- Spacing around PHP 7.4 arrow functions -->
6062
<rule ref="SlevomatCodingStandard.Functions.DisallowEmptyFunction"/> <!-- Empty function must have a comment why is empty -->
6163
<rule ref="SlevomatCodingStandard.Functions.RequireMultiLineCall"/> <!-- Can fix when max line length of function call is exceeded -->
6264
<rule ref="SlevomatCodingStandard.Functions.StaticClosure"/> <!-- Use static closure if not using $this -->
63-
<rule ref="SlevomatCodingStandard.Functions.TrailingCommaInCall"/> <!-- PHP 7.3+ add trailing comma in multiline function call -->
65+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/> <!-- PHP 7.3+ add trailing comma in multiline function call -->
66+
<rule ref="SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration"/> <!-- PHP 8.0+ add trailing comma in multiline function declaration -->
6467
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/> <!-- Check unused variable in use() for closure -->
6568
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/> <!-- Namespace use sort alphabetically -->
6669
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/> <!-- Group use namespaces declaration is disallowed -->

Rules/phpcs-strict.xml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
<rule ref="SlevomatCodingStandard.Operators.DisallowIncrementAndDecrementOperators"/> <!-- Disable use of $i++ must use $i += 1 etc.. -->
6060
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"> <!-- File must have declare strict types with correct spacing -->
6161
<properties>
62-
<property name="newlinesCountBetweenOpenTagAndDeclare" value="2"/>
62+
<property name="linesCountBeforeDeclare" value="1"/>
63+
<property name="linesCountAfterDeclare" value="1"/>
6364
<property name="spacesCountAroundEqualsSign" value="0"/>
6465
</properties>
6566
</rule>
@@ -80,6 +81,13 @@
8081
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation">
8182
<severity>0</severity>
8283
</rule>
84+
<rule ref="SlevomatCodingStandard.TypeHints.UnionTypeHintFormat"> <!-- Checks format of union type hints -->
85+
<properties>
86+
<property name="withSpaces" value="false"/>
87+
<property name="shortNullable" value="true"/>
88+
<property name="nullPosition" value="last"/>
89+
</properties>
90+
</rule>
8391
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/> <!-- Disable comments for constants -->
8492

8593
</ruleset>

SniffsList.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,18 +116,21 @@
116116
- SlevomatCodingStandard.ControlStructures.RequireMultiLineCondition
117117
- SlevomatCodingStandard.ControlStructures.RequireMultiLineTernaryOperator
118118
- SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator
119+
- SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator
119120
- SlevomatCodingStandard.ControlStructures.RequireShortTernaryOperator
120121
- SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition
121122
- SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn
122123
- SlevomatCodingStandard.ControlStructures.UselessTernaryOperator
123124
- SlevomatCodingStandard.Exceptions.DeadCatch
124125
- SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly
126+
- SlevomatCodingStandard.Exceptions.RequireNonCapturingCatch
125127
- SlevomatCodingStandard.Functions.ArrowFunctionDeclaration
126128
- SlevomatCodingStandard.Functions.DisallowEmptyFunction
127129
- SlevomatCodingStandard.Functions.RequireMultiLineCall
128130
- SlevomatCodingStandard.Functions.RequireSingleLineCall
131+
- SlevomatCodingStandard.Functions.RequireTrailingCommaInDeclaration
129132
- SlevomatCodingStandard.Functions.StaticClosure
130-
- SlevomatCodingStandard.Functions.TrailingCommaInCall
133+
- SlevomatCodingStandard.Functions.RequireTrailingCommaInCall
131134
- SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure
132135
- SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses
133136
- SlevomatCodingStandard.Namespaces.DisallowGroupUse
@@ -164,6 +167,7 @@
164167
- SlevomatCodingStandard.TypeHints.PropertyTypeHint
165168
- SlevomatCodingStandard.TypeHints.PropertyTypeHintSpacing
166169
- SlevomatCodingStandard.TypeHints.ReturnTypeHint
170+
- SlevomatCodingStandard.TypeHints.UnionTypeHintFormat
167171
- SlevomatCodingStandard.TypeHints.UselessConstantTypeHint
168172
- SlevomatCodingStandard.Variables.DisallowSuperGlobalVariable
169173
- SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
],
1313
"require": {
1414
"php": "^7.1 || ^8.0",
15-
"slevomat/coding-standard": "^6.4.0"
15+
"slevomat/coding-standard": "^7.0"
1616
}
1717
}

phpcs.example.xml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
<!-- Check folders -->
55
<file>./app</file>
66

7+
<config name="php_version" value="80000"/> <!-- Set target version, for 7.4 set to 70400 etc. -->
8+
79
<arg name="basepath" value="."/> <!-- Strip file basepath from report -->
810
<arg name="colors"/> <!-- Show colors -->
911
<arg value="p"/> <!-- Display progress in report -->
@@ -16,12 +18,23 @@
1618
<exclude name="SlevomatCodingStandard.Namespaces.FullyQualifiedGlobalFunctions.NonFullyQualified"/>
1719

1820
<!-- trailing comma in function call is supported in PHP 7.3 and above, exclude if needed -->
19-
<exclude name="SlevomatCodingStandard.Functions.TrailingCommaInCall"/>
21+
<exclude name="SlevomatCodingStandard.Functions.RequireTrailingCommaInCall"/>
2022
</rule>
2123

2224
<!-- Add set of strict rules if needed -->
2325
<!--
2426
<rule ref="./vendor/arxeiss/coding-standards/Rules/phpcs-strict.xml">
2527
</rule>
2628
-->
29+
30+
<!-- Bring back Useless Annotation errors, which are normally ignored -->
31+
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation">
32+
<severity>5</severity>
33+
</rule>
34+
<rule ref="SlevomatCodingStandard.TypeHints.PropertyTypeHint.UselessAnnotation">
35+
<severity>5</severity>
36+
</rule>
37+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation">
38+
<severity>5</severity>
39+
</rule>
2740
</ruleset>

0 commit comments

Comments
 (0)