Skip to content

Commit e0e1eed

Browse files
committed
Require constructor property promotion
1 parent 720492b commit e0e1eed

File tree

3 files changed

+6
-14
lines changed

3 files changed

+6
-14
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@
144144
<property name="enableMultipleSpacesBetweenModifiersCheck" value="true"/>
145145
</properties>
146146
</rule>
147+
<!-- Require usage of constructor property promotion -->
148+
<rule ref="SlevomatCodingStandard.Classes.RequireConstructorPropertyPromotion"/>
147149
<!-- Forbid uses of multiple traits separated by comma -->
148150
<rule ref="SlevomatCodingStandard.Classes.TraitUseDeclaration"/>
149151
<!-- Require no spaces before trait use, between trait uses and one space after trait uses -->

tests/expected_report.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ tests/input/ControlStructures.php 28 0
1515
tests/input/doc-comment-spacing.php 11 0
1616
tests/input/duplicate-assignment-variable.php 1 0
1717
tests/input/EarlyReturn.php 7 0
18-
tests/input/example-class.php 43 0
18+
tests/input/example-class.php 44 0
1919
tests/input/ExampleBackedEnum.php 3 0
2020
tests/input/Exceptions.php 1 0
2121
tests/input/forbidden-comments.php 14 0
@@ -50,9 +50,9 @@ tests/input/use-ordering.php 1 0
5050
tests/input/useless-semicolon.php 2 0
5151
tests/input/UselessConditions.php 21 0
5252
----------------------------------------------------------------------
53-
A TOTAL OF 428 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
53+
A TOTAL OF 429 ERRORS AND 0 WARNINGS WERE FOUND IN 46 FILES
5454
----------------------------------------------------------------------
55-
PHPCBF CAN FIX 363 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
55+
PHPCBF CAN FIX 364 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
5656
----------------------------------------------------------------------
5757

5858

tests/fixed/example-class.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,10 @@ class Example implements IteratorAggregate
2525
{
2626
private const VERSION = PHP_VERSION - (PHP_MINOR_VERSION * 100) - PHP_PATCH_VERSION;
2727

28-
private int|null $foo = null;
29-
30-
/** @var string[] */
31-
private array $bar;
32-
33-
private bool $baz;
34-
3528
private ControlStructureSniff|int|string|null $baxBax = null;
3629

37-
public function __construct(int|null $foo = null, array $bar = [], bool $baz = false, $baxBax = 'unused')
30+
public function __construct(private int|null $foo = null, private array $bar = [], private bool $baz = false, $baxBax = 'unused')
3831
{
39-
$this->foo = $foo;
40-
$this->bar = $bar;
41-
$this->baz = $baz;
4232
$this->baxBax = $baxBax;
4333
}
4434

0 commit comments

Comments
 (0)