Skip to content

Commit 7e110bb

Browse files
authored
Merge pull request #109 from Majkl578/slevomat-cs-5.0
Upgrade to Slevomat CS 5.0
2 parents e8f939b + b4c2904 commit 7e110bb

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"require": {
2929
"php": "^7.1",
3030
"dealerdirect/phpcodesniffer-composer-installer": "^0.5.0",
31-
"slevomat/coding-standard": "^4.8.6",
31+
"slevomat/coding-standard": "^5.0",
3232
"squizlabs/php_codesniffer": "^3.4.0"
3333
},
3434
"config": {

lib/Doctrine/ruleset.xml

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
<property name="fixable" value="true"/>
107107
</properties>
108108
</rule>
109+
<!-- Forbid empty lines around type declarations -->
110+
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
111+
<properties>
112+
<property name="linesCountAfterOpeningBrace" value="0"/>
113+
<property name="linesCountBeforeClosingBrace" value="0"/>
114+
</properties>
115+
</rule>
109116
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
110117
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
111118
<!-- Forbid uses of multiple traits separated by comma -->
@@ -193,8 +200,6 @@
193200
<rule ref="SlevomatCodingStandard.ControlStructures.AssignmentInCondition"/>
194201
<!-- Forbid fancy yoda conditions -->
195202
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowYodaComparison"/>
196-
<!-- Forbid weak comparisons -->
197-
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
198203
<!-- Require usage of early exit -->
199204
<rule ref="SlevomatCodingStandard.ControlStructures.EarlyExit"/>
200205
<!-- Require language constructs without parentheses -->
@@ -204,7 +209,9 @@
204209
<!-- Require usage of null coalesce operator when possible -->
205210
<rule ref="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator"/>
206211
<!-- Forbid usage of conditions when a simple return can be used -->
207-
<rule ref="SlevomatCodingStandard.ControlStructures.UselessConditionWithReturn"/>
212+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessIfConditionWithReturn"/>
213+
<!-- Forbid usage of boolean-only ternary operator usage (e.g. $foo ? true : false) -->
214+
<rule ref="SlevomatCodingStandard.ControlStructures.UselessTernaryOperator"/>
208215
<!-- Forbid useless unreachable catch blocks -->
209216
<rule ref="SlevomatCodingStandard.Exceptions.DeadCatch"/>
210217
<!-- Require using Throwable instead of Exception -->
@@ -214,7 +221,11 @@
214221
<!-- Forbid unused variables passed to closures via `use` -->
215222
<rule ref="SlevomatCodingStandard.Functions.UnusedInheritedVariablePassedToClosure"/>
216223
<!-- Require use statements to be alphabetically sorted -->
217-
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
224+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses">
225+
<properties>
226+
<property name="psr12Compatible" value="false"/>
227+
</properties>
228+
</rule>
218229
<!-- Forbid fancy group uses -->
219230
<rule ref="SlevomatCodingStandard.Namespaces.DisallowGroupUse"/>
220231
<!-- Forbid multiple use statements on same line -->
@@ -255,6 +266,8 @@
255266
</rule>
256267
<!-- Forbid useless alias for classes, constants and functions -->
257268
<rule ref="SlevomatCodingStandard.Namespaces.UselessAlias"/>
269+
<!-- Forbid weak comparisons -->
270+
<rule ref="SlevomatCodingStandard.Operators.DisallowEqualOperators"/>
258271
<!-- Require the usage of assignment operators, eg `+=`, `.=` when possible -->
259272
<rule ref="SlevomatCodingStandard.Operators.RequireCombinedAssignmentOperator"/>
260273
<!-- forbid argument unpacking for functions specialized by PHP VM -->
@@ -312,13 +325,6 @@
312325
</rule>
313326
<!-- Forbid useless @var for constants -->
314327
<rule ref="SlevomatCodingStandard.TypeHints.UselessConstantTypeHint"/>
315-
<!-- Forbid empty lines around type declarations -->
316-
<rule ref="SlevomatCodingStandard.Types.EmptyLinesAroundTypeBraces">
317-
<properties>
318-
<property name="linesCountAfterOpeningBrace" value="0"/>
319-
<property name="linesCountBeforeClosingBrace" value="0"/>
320-
</properties>
321-
</rule>
322328
<!-- Forbid duplicated variables assignments -->
323329
<rule ref="SlevomatCodingStandard.Variables.DuplicateAssignmentToVariable"/>
324330
<!-- Forbid useless variables -->

tests/expected_report.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ tests/input/UselessConditions.php 20 0
3333
----------------------------------------------------------------------
3434
A TOTAL OF 238 ERRORS AND 0 WARNINGS WERE FOUND IN 27 FILES
3535
----------------------------------------------------------------------
36-
PHPCBF CAN FIX 207 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
36+
PHPCBF CAN FIX 202 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
3737
----------------------------------------------------------------------
3838

3939

tests/fixed/UselessConditions.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,20 @@ public function unecessaryIfMethodForEarlyReturn() : bool
4444

4545
public function uselessIfConditionWithParameter(bool $bool) : bool
4646
{
47-
return ! $bool;
47+
if ($bool) {
48+
return false;
49+
}
50+
51+
return true;
4852
}
4953

5054
public function uselessIfConditionWithBoolMethod() : bool
5155
{
52-
return ! $this->isTrue();
56+
if ($this->isTrue()) {
57+
return false;
58+
}
59+
60+
return true;
5361
}
5462

5563
public function uselessIfConditionWithComplexIf() : bool
@@ -70,7 +78,7 @@ public function uselessIfConditionWithComplexCondition() : bool
7078
public function uselessIfConditionWithTernary() : bool
7179
{
7280
if ($this->isTrue()) {
73-
return $this->isTrulyTrue();
81+
return $this->isTrulyTrue() ? true : false;
7482
}
7583

7684
return false;
@@ -103,12 +111,12 @@ public function uselessTernary() : bool
103111

104112
public function uselessTernaryWithParameter(bool $condition) : bool
105113
{
106-
return $condition;
114+
return $condition ? true : false;
107115
}
108116

109117
public function uselessTernaryWithMethod() : bool
110118
{
111-
return $this->isFalse();
119+
return $this->isFalse() ? true : false;
112120
}
113121

114122
/**

0 commit comments

Comments
 (0)