Skip to content

Commit c665bae

Browse files
authored
Merge pull request #174 from doctrine/new-rule/forbid-constants-same-declaration
Add rule forbidding more than one constant declared per statement
2 parents d45826c + dd0c8d1 commit c665bae

File tree

5 files changed

+20
-8
lines changed

5 files changed

+20
-8
lines changed

lib/Doctrine/ruleset.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@
121121
</rule>
122122
<!-- Forbid LSB for constants (static::FOO) -->
123123
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
124+
<!-- Forbid more than one constant declared per statement -->
125+
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>
124126
<!-- Forbid empty lines around type declarations -->
125127
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
126128
<properties>

tests/expected_report.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ tests/input/assignment-operators.php 4 0
88
tests/input/class-references.php 10 0
99
tests/input/concatenation_spacing.php 24 0
1010
tests/input/constants-no-lsb.php 2 0
11-
tests/input/constants-var.php 4 0
11+
tests/input/constants-var.php 6 0
1212
tests/input/ControlStructures.php 17 0
1313
tests/input/doc-comment-spacing.php 10 0
1414
tests/input/duplicate-assignment-variable.php 1 0
@@ -40,9 +40,9 @@ tests/input/use-ordering.php 1 0
4040
tests/input/useless-semicolon.php 2 0
4141
tests/input/UselessConditions.php 20 0
4242
----------------------------------------------------------------------
43-
A TOTAL OF 297 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
43+
A TOTAL OF 299 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
4444
----------------------------------------------------------------------
45-
PHPCBF CAN FIX 236 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
45+
PHPCBF CAN FIX 238 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
4646
----------------------------------------------------------------------
4747

4848

tests/fixed/constants-var.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66

77
const FOO = 123;
88

9+
const BAR_1 = 1;
10+
const BAR_1 = 2;
11+
912
class Bar
1013
{
1114
public const BAZ = 456;
15+
16+
protected const PROPERTY_1 = '1';
17+
protected const PROPERTY_2 = '2';
1218
}

tests/input/constants-var.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
/** @var int */
88
const FOO = 123;
99

10+
const BAR_1 = 1, BAR_1 = 2;
11+
1012
class Bar
1113
{
1214
/** @var int */
1315
public const BAZ = 456;
16+
17+
protected const PROPERTY_1 = '1', PROPERTY_2 = '2';
1418
}

tests/php-compatibility.patch

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ index 1e809f9..490fcbd 100644
1111
-tests/input/concatenation_spacing.php 24 0
1212
+tests/input/concatenation_spacing.php 49 0
1313
tests/input/constants-no-lsb.php 2 0
14-
tests/input/constants-var.php 4 0
14+
tests/input/constants-var.php 6 0
1515
-tests/input/ControlStructures.php 17 0
1616
+tests/input/ControlStructures.php 27 0
1717
tests/input/doc-comment-spacing.php 10 0
@@ -52,11 +52,11 @@ index 1e809f9..490fcbd 100644
5252
tests/input/useless-semicolon.php 2 0
5353
tests/input/UselessConditions.php 20 0
5454
----------------------------------------------------------------------
55-
-A TOTAL OF 297 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
56-
+A TOTAL OF 371 ERRORS AND 0 WARNINGS WERE FOUND IN 40 FILES
55+
-A TOTAL OF 299 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
56+
+A TOTAL OF 373 ERRORS AND 0 WARNINGS WERE FOUND IN 40 FILES
5757
----------------------------------------------------------------------
58-
-PHPCBF CAN FIX 236 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
59-
+PHPCBF CAN FIX 306 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
58+
-PHPCBF CAN FIX 238 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
59+
+PHPCBF CAN FIX 308 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
6060
----------------------------------------------------------------------
6161

6262

0 commit comments

Comments
 (0)