Skip to content

Commit dba40be

Browse files
committed
Update ruleset for modern (PHP 8+) code
1 parent c628203 commit dba40be

File tree

3 files changed

+36
-9
lines changed

3 files changed

+36
-9
lines changed

MO4/ruleset.xml

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
<!-- exclude sniffs that are disabled on purpose by this standard -->
1515
<exclude name="Symfony.Commenting.ClassComment.Missing"/>
1616
<exclude name="Symfony.Commenting.License"/>
17+
<!-- SlevomatCodingStandard.ControlStructures.RequireYodaComparison supports autofixing -->
18+
<exclude name="Symfony.ControlStructure.YodaConditions.Invalid"/>
19+
<!-- disable forcing of function type hints as we're requiring native types -->
20+
<exclude name="Symfony.Commenting.FunctionComment"/>
1721
</rule>
1822

1923
<!-- Also include PSR12 -->
@@ -131,8 +135,16 @@
131135
</rule>
132136
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
133137
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
138+
<!-- Require use of constructor property promotion -->
139+
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
140+
<!-- Forbid static:: in final class -->
141+
<rule ref="SlevomatCodingStandard.Classes.UselessLateStaticBinding"/>
142+
<!-- Forbid empty comments-->
143+
<rule ref="SlevomatCodingStandard.Commenting.EmptyComment"/>
134144
<!-- report invalid format of inline phpDocs with @var -->
135145
<rule ref="SlevomatCodingStandard.Commenting.InlineDocCommentDeclaration"/>
146+
<!-- Forbid useless function doc comments -->
147+
<rule ref="SlevomatCodingStandard.Commenting.UselessFunctionDocComment"/>
136148
<!-- Forbid useless @inheritDoc comments -->
137149
<rule ref="SlevomatCodingStandard.Commenting.UselessInheritDocComment"/>
138150
<!-- Forbid assignments in conditions -->
@@ -159,13 +171,21 @@
159171
<rule ref="SlevomatCodingStandard.ControlStructures.NewWithParentheses"/>
160172
<!-- Require usage of null coalesce operator when possible -->
161173
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
174+
<!-- Require usage of null coalesce equal operator when possible -->
175+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceEqualOperator"/>
176+
<!-- Require usage of null safe operator when possible -->
177+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullSafeObjectOperator"/>
162178
<!-- Require usage of ternary operator when possible -->
163179
<rule ref="SlevomatCodingStandard.ControlStructures.RequireTernaryOperator">
164180
<!-- But multiline is useful for readability -->
165181
<properties>
166182
<property name="ignoreMultiLine" value="true"/>
167183
</properties>
168184
</rule>
185+
<!-- Require Yoda comparisons -->
186+
<rule ref="SlevomatCodingStandard.ControlStructures.RequireYodaComparison"/>
187+
<!-- Formatting of arrow functions -->
188+
<rule ref="SlevomatCodingStandard.Functions.ArrowFunctionDeclaration"/>
169189
<!-- Enforce consistent spacing of named arguments -->
170190
<rule ref="SlevomatCodingStandard.Functions.NamedArgumentSpacing"/>
171191
<!-- Require static closures for microoptimization -->
@@ -237,10 +257,10 @@
237257
</properties>
238258
</rule>
239259
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.UselessAnnotation">
240-
<severity>0</severity>
260+
<severity>9</severity>
241261
</rule>
242262
<rule ref="SlevomatCodingStandard.TypeHints.ParameterTypeHint.MissingTraversableTypeHintSpecification">
243-
<severity>0</severity>
263+
<severity>9</severity>
244264
</rule>
245265
<!-- Require return type hints to be declared -->
246266
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint">
@@ -251,10 +271,19 @@
251271
</properties>
252272
</rule>
253273
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.UselessAnnotation">
254-
<severity>0</severity>
274+
<severity>9</severity>
255275
</rule>
256276
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification">
257-
<severity>0</severity>
277+
<severity>9</severity>
278+
</rule>
279+
<!-- DNF (union / intersection) type hint formatting -->
280+
<rule ref="SlevomatCodingStandard.TypeHints.DNFTypeHintFormat">
281+
<properties>
282+
<property name="withSpacesAroundOperators" value="yes"/>
283+
<property name="withSpacesInsideParentheses" value="no"/>
284+
<property name="shortNullable" value="yes"/>
285+
<property name="nullPosition" value="last"/>
286+
</properties>
258287
</rule>
259288
<!-- Forbid useless @var for constants -->
260289
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"php": "^8.1",
2727
"dealerdirect/phpcodesniffer-composer-installer": "^0.7 || ^1.0",
2828
"escapestudios/symfony2-coding-standard": "^3.16.0",
29-
"slevomat/coding-standard": "^8.14",
29+
"slevomat/coding-standard": "^8.20",
3030
"squizlabs/php_codesniffer": "^3.8.0"
3131
},
3232
"require-dev": {

integrationtests/testfile.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ public function __construct(string $dummy)
3939
}
4040

4141
/**
42-
* @return string
43-
*
4442
* @deprecated
4543
*/
4644
public function someDeprecatedMethod(): string
@@ -53,8 +51,8 @@ public function someDeprecatedMethod(): string
5351
/**
5452
* Transforms the input given as first argument.
5553
*
56-
* @param bool|string $dummy Some argument description
57-
* @param array $options An options collection to be used within the transformation
54+
* @param bool|string $dummy Some argument description
55+
* @param array<string> $options An options collection to be used within the transformation
5856
*
5957
* @return string|null The transformed input
6058
*

0 commit comments

Comments
 (0)