From c6ce8b03c673b1e8d8da06ca41fa034c96b1f5c1 Mon Sep 17 00:00:00 2001 From: Jeffrey Angenent <1571879+devfrey@users.noreply.github.com> Date: Mon, 8 Dec 2025 14:42:34 +0100 Subject: [PATCH] Skip static properties in `EnforceReadonlyPublicPropertyRule` --- src/Rule/EnforceReadonlyPublicPropertyRule.php | 2 +- tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-81.php | 4 ++++ tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-84.php | 4 ++++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Rule/EnforceReadonlyPublicPropertyRule.php b/src/Rule/EnforceReadonlyPublicPropertyRule.php index e7f0776..b6b77dc 100644 --- a/src/Rule/EnforceReadonlyPublicPropertyRule.php +++ b/src/Rule/EnforceReadonlyPublicPropertyRule.php @@ -41,7 +41,7 @@ public function processNode( return []; } - if (!$node->isPublic() || $node->isReadOnly() || $node->hasHooks() || $node->isPrivateSet() || $node->isProtectedSet()) { + if (!$node->isPublic() || $node->isReadOnly() || $node->hasHooks() || $node->isPrivateSet() || $node->isProtectedSet() || $node->isStatic()) { return []; } diff --git a/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-81.php b/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-81.php index 90a466f..23cde24 100644 --- a/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-81.php +++ b/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-81.php @@ -12,6 +12,8 @@ trait MyTrait { private string $private; + public static string $static; + } class MyClass { @@ -26,6 +28,8 @@ class MyClass { private int $bag; + public static string $static; + } readonly class MyReadonlyClass { diff --git a/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-84.php b/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-84.php index 2da599c..43d4e27 100644 --- a/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-84.php +++ b/tests/Rule/data/EnforceReadonlyPublicPropertyRule/code-84.php @@ -14,6 +14,8 @@ trait MyTrait { private string $private; + public static string $static; + } class MyClass { @@ -30,6 +32,8 @@ class MyClass { private int $bag; + public static string $static; + } readonly class MyReadonlyClass {