Skip to content

Add rule forbidding more than one constant declared per statement #174

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@
</rule>
<!-- Forbid LSB for constants (static::FOO) -->
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
<!-- Forbid more than one constant declared per statement -->
<rule ref="SlevomatCodingStandard.Classes.DisallowMultiConstantDefinition"/>
<!-- Forbid empty lines around type declarations -->
<rule ref="SlevomatCodingStandard.Classes.EmptyLinesAroundClassBraces">
<properties>
Expand Down
6 changes: 3 additions & 3 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ tests/input/assignment-operators.php 4 0
tests/input/class-references.php 10 0
tests/input/concatenation_spacing.php 24 0
tests/input/constants-no-lsb.php 2 0
tests/input/constants-var.php 4 0
tests/input/constants-var.php 6 0
tests/input/ControlStructures.php 17 0
tests/input/doc-comment-spacing.php 10 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -40,9 +40,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 297 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
A TOTAL OF 299 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 236 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 238 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


6 changes: 6 additions & 0 deletions tests/fixed/constants-var.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

const FOO = 123;

const BAR_1 = 1;
const BAR_1 = 2;

class Bar
{
public const BAZ = 456;

protected const PROPERTY_1 = '1';
protected const PROPERTY_2 = '2';
Comment on lines 14 to +17
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spacing between constants will be proposed in a separate PR.

Spoiler: SlevomatCodingStandard.Classes.ConstantSpacing.

}
4 changes: 4 additions & 0 deletions tests/input/constants-var.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
/** @var int */
const FOO = 123;

const BAR_1 = 1, BAR_1 = 2;

class Bar
{
/** @var int */
public const BAZ = 456;

protected const PROPERTY_1 = '1', PROPERTY_2 = '2';
}
10 changes: 5 additions & 5 deletions tests/php-compatibility.patch
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ index 1e809f9..490fcbd 100644
-tests/input/concatenation_spacing.php 24 0
+tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
tests/input/constants-var.php 4 0
tests/input/constants-var.php 6 0
-tests/input/ControlStructures.php 17 0
+tests/input/ControlStructures.php 27 0
tests/input/doc-comment-spacing.php 10 0
Expand Down Expand Up @@ -52,11 +52,11 @@ index 1e809f9..490fcbd 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 297 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
+A TOTAL OF 371 ERRORS AND 0 WARNINGS WERE FOUND IN 40 FILES
-A TOTAL OF 299 ERRORS AND 0 WARNINGS WERE FOUND IN 36 FILES
+A TOTAL OF 373 ERRORS AND 0 WARNINGS WERE FOUND IN 40 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 236 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 306 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 238 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 308 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down