Skip to content

Commit

Permalink
feat: enforce spaces between constants
Browse files Browse the repository at this point in the history
  • Loading branch information
simPod committed Jul 10, 2022
1 parent 51e2045 commit f0ae45f
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Expand Up @@ -122,6 +122,8 @@
<property name="fixable" value="true"/>
</properties>
</rule>
<!-- Enforce consistent constant spacing -->
<rule ref="SlevomatCodingStandard.Classes.ConstantSpacing"/>
<!-- Forbid LSB for constants (static::FOO) -->
<rule ref="SlevomatCodingStandard.Classes.DisallowLateStaticBindingForConstants"/>
<!-- Forbid more than one constant declared per statement -->
Expand Down
2 changes: 1 addition & 1 deletion tests/expected_report.txt
Expand Up @@ -48,7 +48,7 @@ tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 316 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


11 changes: 11 additions & 0 deletions tests/fixed/constants-var.php
Expand Up @@ -4,6 +4,8 @@

namespace ConstantsVar;

// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses, Squiz.Classes.ClassFileName.NoMatch

const FOO = 123;

const BAR_1 = 1;
Expand All @@ -16,3 +18,12 @@ class Bar
protected const PROPERTY_1 = '1';
protected const PROPERTY_2 = '2';
}


class Spacing
{
public const FOO = 'bar';
public const BAR = 'bar';

public const BAZ = 'baz';
}
12 changes: 12 additions & 0 deletions tests/input/constants-var.php
Expand Up @@ -4,6 +4,8 @@

namespace ConstantsVar;

// phpcs:disable PSR1.Classes.ClassDeclaration.MultipleClasses, Squiz.Classes.ClassFileName.NoMatch

/** @var int */
const FOO = 123;

Expand All @@ -16,3 +18,13 @@ class Bar

protected const PROPERTY_1 = '1', PROPERTY_2 = '2';
}


class Spacing
{
public const FOO = 'bar';
public const BAR = 'bar';


public const BAZ = 'baz';
}
2 changes: 1 addition & 1 deletion tests/php73-compatibility.patch
Expand Up @@ -17,7 +17,7 @@ index 1d5a7d3..fae9e70 100644
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 383 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 316 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/php74-compatibility.patch
Expand Up @@ -39,7 +39,7 @@ index 1d5a7d3..91e97e7 100644
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 392 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 316 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 326 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/php80-compatibility.patch
Expand Up @@ -52,7 +52,7 @@ index 1d5a7d3..03460f2 100644
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 420 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 316 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 354 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expand Down
2 changes: 1 addition & 1 deletion tests/php81-compatibility.patch
Expand Up @@ -53,7 +53,7 @@ index 1d5a7d3..e9394b1 100644
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 426 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 316 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 360 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------

Expand Down

0 comments on commit f0ae45f

Please sign in to comment.