Skip to content

Commit e346324

Browse files
committed
feat: run PropertyDeclaration on promoted properties
- check promoted properties - check multiple spaces between modifiers - bump Slevomat CS to v8.1
1 parent 2192057 commit e346324

File tree

4 files changed

+63
-22
lines changed

4 files changed

+63
-22
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"require": {
2424
"php": "^7.2 || ^8.0",
2525
"dealerdirect/phpcodesniffer-composer-installer": "^0.6.2 || ^0.7",
26-
"slevomat/coding-standard": "^8",
26+
"slevomat/coding-standard": "^8.1",
2727
"squizlabs/php_codesniffer": "^3.7"
2828
},
2929
"config": {

lib/Doctrine/ruleset.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,12 @@
134134
<!-- Require usage of ::class instead of __CLASS__, get_class(), get_class($this), get_called_class() and get_parent_class() -->
135135
<rule ref="SlevomatCodingStandard.Classes.ModernClassNameReference"/>
136136
<!-- https://github.com/slevomat/coding-standard#slevomatcodingstandardclassespropertydeclaration- -->
137-
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration"/>
137+
<rule ref="SlevomatCodingStandard.Classes.PropertyDeclaration">
138+
<properties>
139+
<property name="checkPromoted" value="true"/>
140+
<property name="enableMultipleSpacesBetweenModifiersCheck" value="true"/>
141+
</properties>
142+
</rule>
138143
<!-- Forbid uses of multiple traits separated by comma -->
139144
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
140145
<!-- Require no spaces before trait use, between trait uses and one space after trait uses -->

tests/php80-compatibility.patch

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2-
index 476a58b..54630dd 100644
2+
index 1d5a7d3..bfdc3f5 100644
33
--- a/tests/expected_report.txt
44
+++ b/tests/expected_report.txt
5-
@@ -14,41 +14,43 @@ tests/input/constants-var.php 6 0
5+
@@ -14,23 +14,24 @@ tests/input/constants-var.php 6 0
66
tests/input/ControlStructures.php 28 0
77
tests/input/doc-comment-spacing.php 11 0
88
tests/input/duplicate-assignment-variable.php 1 0
@@ -29,14 +29,13 @@ index 476a58b..54630dd 100644
2929
-tests/input/PropertyDeclaration.php 6 0
3030
-tests/input/return_type_on_closures.php 21 0
3131
-tests/input/return_type_on_methods.php 17 0
32-
+tests/input/PropertyDeclaration.php 7 0
32+
+tests/input/PropertyDeclaration.php 11 0
3333
+tests/input/return_type_on_closures.php 26 0
3434
+tests/input/return_type_on_methods.php 22 0
3535
tests/input/semicolon_spacing.php 3 0
3636
tests/input/single-line-array-spacing.php 5 0
3737
tests/input/spread-operator.php 6 0
38-
tests/input/static-closures.php 1 0
39-
tests/input/strings.php 1 0
38+
@@ -39,16 +40,17 @@ tests/input/strings.php 1 0
4039
tests/input/superfluous-naming.php 11 0
4140
tests/input/test-case.php 8 0
4241
tests/input/trailing_comma_on_array.php 1 0
@@ -51,15 +50,15 @@ index 476a58b..54630dd 100644
5150
+tests/input/UselessConditions.php 21 0
5251
----------------------------------------------------------------------
5352
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
54-
+A TOTAL OF 412 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
53+
+A TOTAL OF 416 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
5554
----------------------------------------------------------------------
5655
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
57-
+PHPCBF CAN FIX 346 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
56+
+PHPCBF CAN FIX 350 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5857
----------------------------------------------------------------------
5958

6059

6160
diff --git a/tests/fixed/EarlyReturn.php b/tests/fixed/EarlyReturn.php
62-
index 5a82a93..7d5eb01 100644
61+
index caf1dbb..fc734db 100644
6362
--- a/tests/fixed/EarlyReturn.php
6463
+++ b/tests/fixed/EarlyReturn.php
6564
@@ -11,7 +11,7 @@ class EarlyReturn
@@ -94,15 +93,20 @@ index 57d9f2b..5493471 100644
9493
public function fcn(string $A): void
9594
{
9695
diff --git a/tests/fixed/PropertyDeclaration.php b/tests/fixed/PropertyDeclaration.php
97-
index 5c3f27b..7f286ad 100644
96+
index 5c3f27b..7821d5c 100644
9897
--- a/tests/fixed/PropertyDeclaration.php
9998
+++ b/tests/fixed/PropertyDeclaration.php
100-
@@ -9,5 +9,5 @@ final class PropertyDeclaration
99+
@@ -9,5 +9,10 @@ final class PropertyDeclaration
101100
public bool $boolPropertyWithDefaultValue = false;
102101
public string $stringProperty;
103102
public int $intProperty;
104103
- public ?string $nullableString = null;
105104
+ public string|null $nullableString = null;
105+
+
106+
+ public function __construct(
107+
+ public Foo $foo,
108+
+ ) {
109+
+ }
106110
}
107111
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php
108112
index 6e5cca4..c5fdccb 100644
@@ -343,6 +347,20 @@ index 10e6f34..5e26ed8 100644
343347
- private $x = 1;
344348
+ private int|string|null $x = 1;
345349
}
350+
diff --git a/tests/input/PropertyDeclaration.php b/tests/input/PropertyDeclaration.php
351+
index 0891e12..4eb8164 100644
352+
--- a/tests/input/PropertyDeclaration.php
353+
+++ b/tests/input/PropertyDeclaration.php
354+
@@ -10,4 +10,9 @@ final class PropertyDeclaration
355+
public string $stringProperty;
356+
public int $intProperty;
357+
public ? string $nullableString = null;
358+
+
359+
+ public function __construct(
360+
+ public Foo $foo
361+
+ ) {
362+
+ }
363+
}
346364
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php
347365
index 6e5cca4..1d24bb6 100644
348366
--- a/tests/input/TrailingCommaOnFunctions.php

tests/php81-compatibility.patch

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
2-
index 476a58b..54630dd 100644
2+
index 1d5a7d3..86e94e3 100644
33
--- a/tests/expected_report.txt
44
+++ b/tests/expected_report.txt
5-
@@ -14,41 +14,43 @@ tests/input/constants-var.php 6 0
5+
@@ -14,23 +14,24 @@ tests/input/constants-var.php 6 0
66
tests/input/ControlStructures.php 28 0
77
tests/input/doc-comment-spacing.php 11 0
88
tests/input/duplicate-assignment-variable.php 1 0
@@ -29,14 +29,13 @@ index 476a58b..54630dd 100644
2929
-tests/input/PropertyDeclaration.php 6 0
3030
-tests/input/return_type_on_closures.php 21 0
3131
-tests/input/return_type_on_methods.php 17 0
32-
+tests/input/PropertyDeclaration.php 7 0
32+
+tests/input/PropertyDeclaration.php 14 0
3333
+tests/input/return_type_on_closures.php 26 0
3434
+tests/input/return_type_on_methods.php 22 0
3535
tests/input/semicolon_spacing.php 3 0
3636
tests/input/single-line-array-spacing.php 5 0
3737
tests/input/spread-operator.php 6 0
38-
tests/input/static-closures.php 1 0
39-
tests/input/strings.php 1 0
38+
@@ -39,16 +40,17 @@ tests/input/strings.php 1 0
4039
tests/input/superfluous-naming.php 11 0
4140
tests/input/test-case.php 8 0
4241
tests/input/trailing_comma_on_array.php 1 0
@@ -51,15 +50,15 @@ index 476a58b..54630dd 100644
5150
+tests/input/UselessConditions.php 21 0
5251
----------------------------------------------------------------------
5352
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
54-
+A TOTAL OF 412 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
53+
+A TOTAL OF 419 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
5554
----------------------------------------------------------------------
5655
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
57-
+PHPCBF CAN FIX 346 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
56+
+PHPCBF CAN FIX 353 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5857
----------------------------------------------------------------------
5958

6059

6160
diff --git a/tests/fixed/EarlyReturn.php b/tests/fixed/EarlyReturn.php
62-
index 5a82a93..7d5eb01 100644
61+
index caf1dbb..fc734db 100644
6362
--- a/tests/fixed/EarlyReturn.php
6463
+++ b/tests/fixed/EarlyReturn.php
6564
@@ -11,7 +11,7 @@ class EarlyReturn
@@ -94,15 +93,20 @@ index 57d9f2b..5493471 100644
9493
public function fcn(string $A): void
9594
{
9695
diff --git a/tests/fixed/PropertyDeclaration.php b/tests/fixed/PropertyDeclaration.php
97-
index 5c3f27b..7f286ad 100644
96+
index 5c3f27b..9703897 100644
9897
--- a/tests/fixed/PropertyDeclaration.php
9998
+++ b/tests/fixed/PropertyDeclaration.php
100-
@@ -9,5 +9,5 @@ final class PropertyDeclaration
99+
@@ -9,5 +9,10 @@ final class PropertyDeclaration
101100
public bool $boolPropertyWithDefaultValue = false;
102101
public string $stringProperty;
103102
public int $intProperty;
104103
- public ?string $nullableString = null;
105104
+ public string|null $nullableString = null;
105+
+
106+
+ public function __construct(
107+
+ public readonly Foo $foo,
108+
+ ) {
109+
+ }
106110
}
107111
diff --git a/tests/fixed/TrailingCommaOnFunctions.php b/tests/fixed/TrailingCommaOnFunctions.php
108112
index 6e5cca4..c5fdccb 100644
@@ -343,6 +347,20 @@ index 10e6f34..5e26ed8 100644
343347
- private $x = 1;
344348
+ private int|string|null $x = 1;
345349
}
350+
diff --git a/tests/input/PropertyDeclaration.php b/tests/input/PropertyDeclaration.php
351+
index 0891e12..acdc445 100644
352+
--- a/tests/input/PropertyDeclaration.php
353+
+++ b/tests/input/PropertyDeclaration.php
354+
@@ -10,4 +10,9 @@ final class PropertyDeclaration
355+
public string $stringProperty;
356+
public int $intProperty;
357+
public ? string $nullableString = null;
358+
+
359+
+ public function __construct(
360+
+ public readonly Foo $foo,
361+
+ ) {
362+
+ }
363+
}
346364
diff --git a/tests/input/TrailingCommaOnFunctions.php b/tests/input/TrailingCommaOnFunctions.php
347365
index 6e5cca4..1d24bb6 100644
348366
--- a/tests/input/TrailingCommaOnFunctions.php

0 commit comments

Comments
 (0)