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 6da8a49
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 20 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
6 changes: 3 additions & 3 deletions tests/expected_report.txt
Expand Up @@ -10,7 +10,7 @@ tests/input/binary_operators.php 9 0
tests/input/class-references.php 10 0
tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
tests/input/constants-var.php 6 0
tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -46,9 +46,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


13 changes: 13 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,14 @@ 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';

/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
private const BAM = 1234;
}
15 changes: 15 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,16 @@ class Bar

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

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


public const BAZ = 'baz';


/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
private const BAM = 1234;
}
8 changes: 4 additions & 4 deletions tests/php73-compatibility.patch
Expand Up @@ -14,11 +14,11 @@ index 1d5a7d3..fae9e70 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-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
-A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 384 ERRORS AND 0 WARNINGS WERE FOUND IN 43 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 318 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
6 changes: 3 additions & 3 deletions tests/php74-compatibility.patch
Expand Up @@ -36,11 +36,11 @@ index 1d5a7d3..91e97e7 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 381 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
-A TOTAL OF 382 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 326 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 328 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
10 changes: 5 additions & 5 deletions tests/php80-compatibility.patch
Expand Up @@ -2,7 +2,7 @@ diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 1d5a7d3..03460f2 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -14,23 +14,24 @@ tests/input/constants-var.php 6 0
@@ -14,23 +14,24 @@ tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -49,11 +49,11 @@ index 1d5a7d3..03460f2 100644
-tests/input/UselessConditions.php 20 0
+tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-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
-A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 421 ERRORS AND 0 WARNINGS WERE FOUND IN 44 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 354 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 356 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down
10 changes: 5 additions & 5 deletions tests/php81-compatibility.patch
Expand Up @@ -2,7 +2,7 @@ diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 1d5a7d3..e9394b1 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -14,23 +14,25 @@ tests/input/constants-var.php 6 0
@@ -14,23 +14,25 @@ tests/input/constants-var.php 7 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
Expand Down Expand Up @@ -50,11 +50,11 @@ index 1d5a7d3..e9394b1 100644
-tests/input/UselessConditions.php 20 0
+tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-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
-A TOTAL OF 382 ERRORS AND 0 WARNINGS WERE FOUND IN 42 FILES
+A TOTAL OF 427 ERRORS AND 0 WARNINGS WERE FOUND IN 45 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 315 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 360 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 317 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 362 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down

0 comments on commit 6da8a49

Please sign in to comment.