Skip to content
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

feat: enable SlevomatCodingStandard.TypeHints.ClassConstantTypeHint #327

Open
wants to merge 2 commits into
base: 13.0.x
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand Down Expand Up @@ -132,6 +134,8 @@ jobs:
- "8.0"
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout"
Expand Down
14 changes: 14 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,20 @@ update-compatibility-patch-80:
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php80-compatibility.patch && git apply -R tests/php80-compatibility.patch
@git commit -m 'Update compatibility patch' tests/php80-compatibility.patch

update-compatibility-patch-81:
@git apply tests/php81-compatibility.patch --allow-empty
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php81-compatibility.patch && git apply -R tests/php81-compatibility.patch --allow-empty
@git commit -m 'Update compatibility patch' tests/php81-compatibility.patch

update-compatibility-patch-82:
@git apply tests/php82-compatibility.patch --allow-empty
@printf "Please open your editor and apply your changes\n"
@until [ "$${compatibility_resolved}" == "y" ]; do read -p "Have finished your changes (y|n)? " compatibility_resolved; done && compatibility_resolved=
@git diff -- tests/expected_report.txt tests/fixed tests/input > .tmp-patch && mv .tmp-patch tests/php82-compatibility.patch && git apply -R tests/php82-compatibility.patch --allow-empty
@git commit -m 'Update compatibility patch' tests/php82-compatibility.patch

vendor: composer.json
composer update
touch -c vendor
2 changes: 2 additions & 0 deletions lib/Doctrine/ruleset.xml
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@
<rule ref="SlevomatCodingStandard.PHP.ShortList"/>
<!-- Forbid use of longhand cast operators -->
<rule ref="SlevomatCodingStandard.PHP.TypeCast"/>
<!-- Check for missing typehints in case they can be declared natively. Report useless @var annotation (or whole documentation comment) because the type of constant is always clear. -->
<rule ref="SlevomatCodingStandard.TypeHints.ClassConstantTypeHint"/>
<!-- Require presence of declare(strict_types=1) -->
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
Expand Down
8 changes: 4 additions & 4 deletions tests/expected_report.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ tests/input/class-references.php 10 2
tests/input/ClassPropertySpacing.php 2 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 13 0
tests/input/ControlStructures.php 28 0
tests/input/doc-comment-spacing.php 11 0
tests/input/duplicate-assignment-variable.php 1 0
tests/input/EarlyReturn.php 7 0
tests/input/example-class.php 47 0
tests/input/example-class.php 48 0
tests/input/ExampleBackedEnum.php 5 0
tests/input/Exceptions.php 1 0
tests/input/forbidden-comments.php 14 0
Expand Down Expand Up @@ -54,9 +54,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
A TOTAL OF 466 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
A TOTAL OF 474 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
----------------------------------------------------------------------
PHPCBF CAN FIX 382 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
PHPCBF CAN FIX 389 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


2 changes: 1 addition & 1 deletion tests/fixed/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ControlStructures
{
private const VERSION = PHP_VERSION;
private const int VERSION = PHP_VERSION;

/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
Expand Down
2 changes: 2 additions & 0 deletions tests/fixed/constants-no-lsb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Test;

// phpcs:disable SlevomatCodingStandard.TypeHints.ClassConstantTypeHint

class ConstantLsb
{
public const A = 123;
Expand Down
14 changes: 7 additions & 7 deletions tests/fixed/constants-var.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@

class Bar
{
public const BAZ = 456;
public const int BAZ = 456;

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

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

public const BAZ = 'baz';
public const string BAZ = 'baz';

/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
private const BAM = 1234;
private const int BAM = 1234;
}
2 changes: 1 addition & 1 deletion tests/input/ControlStructures.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

class ControlStructures
{
private const VERSION = PHP_VERSION;
private const int VERSION = PHP_VERSION;

/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
Expand Down
2 changes: 2 additions & 0 deletions tests/input/constants-no-lsb.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Test;

// phpcs:disable SlevomatCodingStandard.TypeHints.ClassConstantTypeHint

class ConstantLsb
{
public const A = 123;
Expand Down
72 changes: 63 additions & 9 deletions tests/php74-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 087995d..5284a56 100644
index 8547171..f01ece0 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -17,26 +17,23 @@ tests/input/constants-var.php 6 0
@@ -13,30 +13,27 @@ tests/input/class-references.php 10 2
tests/input/ClassPropertySpacing.php 2 0
tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
-tests/input/constants-var.php 13 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
-tests/input/EarlyReturn.php 7 0
-tests/input/example-class.php 47 0
-tests/input/example-class.php 48 0
-tests/input/ExampleBackedEnum.php 5 0
-tests/input/Exceptions.php 1 0
+tests/input/EarlyReturn.php 6 0
Expand Down Expand Up @@ -50,18 +55,27 @@ index 087995d..5284a56 100644
-tests/input/UselessConditions.php 21 0
+tests/input/UselessConditions.php 20 0
----------------------------------------------------------------------
-A TOTAL OF 466 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 428 ERRORS AND 2 WARNINGS WERE FOUND IN 47 FILES
-A TOTAL OF 474 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 429 ERRORS AND 2 WARNINGS WERE FOUND IN 47 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 382 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 344 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 389 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 345 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


diff --git a/tests/fixed/ControlStructures.php b/tests/fixed/ControlStructures.php
index f8f7f65..a653086 100644
index 480e419..a653086 100644
--- a/tests/fixed/ControlStructures.php
+++ b/tests/fixed/ControlStructures.php
@@ -11,7 +11,7 @@ use const PHP_VERSION;

class ControlStructures
{
- private const int VERSION = PHP_VERSION;
+ private const VERSION = PHP_VERSION;

/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
@@ -104,7 +104,7 @@ class ControlStructures

try {
Expand Down Expand Up @@ -192,6 +206,37 @@ index 71e0cfb..2151b17 100644
{
if (! $this->isAdmin) {
return null;
diff --git a/tests/fixed/constants-var.php b/tests/fixed/constants-var.php
index f10c235..d4268cb 100644
--- a/tests/fixed/constants-var.php
+++ b/tests/fixed/constants-var.php
@@ -13,19 +13,19 @@ const BAR_1 = 2;

class Bar
{
- public const int BAZ = 456;
+ public const BAZ = 456;

- protected const string PROPERTY_1 = '1';
- protected const string PROPERTY_2 = '2';
+ protected const PROPERTY_1 = '1';
+ protected const PROPERTY_2 = '2';
}

class Spacing
{
- public const string FOO = 'bar';
- public const string BAR = 'bar';
+ public const FOO = 'bar';
+ public const BAR = 'bar';

- public const string BAZ = 'baz';
+ public const BAZ = 'baz';

/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
- private const int BAM = 1234;
+ private const BAM = 1234;
}
diff --git a/tests/fixed/example-class.php b/tests/fixed/example-class.php
index 4988dab..c31e53f 100644
--- a/tests/fixed/example-class.php
Expand Down Expand Up @@ -349,9 +394,18 @@ index 5e26ed8..bfa6d4f 100644
+ private $x = 1;
}
diff --git a/tests/input/ControlStructures.php b/tests/input/ControlStructures.php
index 73944e3..a0e0b2e 100644
index 7c20d0e..a0e0b2e 100644
--- a/tests/input/ControlStructures.php
+++ b/tests/input/ControlStructures.php
@@ -11,7 +11,7 @@ use const PHP_VERSION;

class ControlStructures
{
- private const int VERSION = PHP_VERSION;
+ private const VERSION = PHP_VERSION;

/** @return iterable<int> */
public function varAndIfNoSpaceBetween(): iterable
@@ -93,7 +93,7 @@ class ControlStructures
}
try {
Expand Down
53 changes: 46 additions & 7 deletions tests/php80-compatibility.patch
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 087995d..f99aa86 100644
index 9b19b9e..760ee4a 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -19,7 +19,6 @@ tests/input/doc-comment-spacing.php 11 0
@@ -13,13 +13,12 @@ tests/input/class-references.php 10 2
tests/input/ClassPropertySpacing.php 2 0
tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
-tests/input/constants-var.php 13 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
tests/input/EarlyReturn.php 7 0
tests/input/example-class.php 47 0
-tests/input/example-class.php 48 0
-tests/input/ExampleBackedEnum.php 5 0
+tests/input/example-class.php 47 0
tests/input/Exceptions.php 1 0
tests/input/forbidden-comments.php 14 0
tests/input/forbidden-functions.php 6 0
Expand All @@ -23,11 +31,11 @@ index 087995d..f99aa86 100644
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-A TOTAL OF 466 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 458 ERRORS AND 2 WARNINGS WERE FOUND IN 49 FILES
-A TOTAL OF 474 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 459 ERRORS AND 2 WARNINGS WERE FOUND IN 49 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 382 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 374 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
-PHPCBF CAN FIX 389 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 375 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


Expand Down Expand Up @@ -63,6 +71,37 @@ index 9703897..7821d5c 100644
) {
}
}
diff --git a/tests/fixed/constants-var.php b/tests/fixed/constants-var.php
index f10c235..d4268cb 100644
--- a/tests/fixed/constants-var.php
+++ b/tests/fixed/constants-var.php
@@ -13,19 +13,19 @@ const BAR_1 = 2;

class Bar
{
- public const int BAZ = 456;
+ public const BAZ = 456;

- protected const string PROPERTY_1 = '1';
- protected const string PROPERTY_2 = '2';
+ protected const PROPERTY_1 = '1';
+ protected const PROPERTY_2 = '2';
}

class Spacing
{
- public const string FOO = 'bar';
- public const string BAR = 'bar';
+ public const FOO = 'bar';
+ public const BAR = 'bar';

- public const string BAZ = 'baz';
+ public const BAZ = 'baz';

/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
- private const int BAM = 1234;
+ private const BAM = 1234;
}
diff --git a/tests/input/ExampleBackedEnum.php b/tests/input/ExampleBackedEnum.php
index 3b09f47..fe54eb9 100644
--- a/tests/input/ExampleBackedEnum.php
Expand Down
62 changes: 62 additions & 0 deletions tests/php81-compatibility.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
diff --git a/tests/expected_report.txt b/tests/expected_report.txt
index 8547171..a7a42fa 100644
--- a/tests/expected_report.txt
+++ b/tests/expected_report.txt
@@ -13,12 +13,12 @@ tests/input/class-references.php 10 2
tests/input/ClassPropertySpacing.php 2 0
tests/input/concatenation_spacing.php 49 0
tests/input/constants-no-lsb.php 2 0
-tests/input/constants-var.php 13 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
tests/input/EarlyReturn.php 7 0
-tests/input/example-class.php 48 0
+tests/input/example-class.php 47 0
tests/input/ExampleBackedEnum.php 5 0
tests/input/Exceptions.php 1 0
tests/input/forbidden-comments.php 14 0
@@ -54,9 +54,9 @@ tests/input/use-ordering.php 1 0
tests/input/useless-semicolon.php 2 0
tests/input/UselessConditions.php 21 0
----------------------------------------------------------------------
-A TOTAL OF 474 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
+A TOTAL OF 467 ERRORS AND 2 WARNINGS WERE FOUND IN 50 FILES
----------------------------------------------------------------------
-PHPCBF CAN FIX 389 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
+PHPCBF CAN FIX 383 OF THESE SNIFF VIOLATIONS AUTOMATICALLY
----------------------------------------------------------------------


diff --git a/tests/fixed/constants-var.php b/tests/fixed/constants-var.php
index f10c235..d4268cb 100644
--- a/tests/fixed/constants-var.php
+++ b/tests/fixed/constants-var.php
@@ -13,19 +13,19 @@ const BAR_1 = 2;

class Bar
{
- public const int BAZ = 456;
+ public const BAZ = 456;

- protected const string PROPERTY_1 = '1';
- protected const string PROPERTY_2 = '2';
+ protected const PROPERTY_1 = '1';
+ protected const PROPERTY_2 = '2';
}

class Spacing
{
- public const string FOO = 'bar';
- public const string BAR = 'bar';
+ public const FOO = 'bar';
+ public const BAR = 'bar';

- public const string BAZ = 'baz';
+ public const BAZ = 'baz';

/** Brevis, primus coordinataes foris promissio de varius, barbatus heuretes. */
- private const int BAM = 1234;
+ private const BAM = 1234;
}
Loading
Loading