Skip to content

[deprecation] Deprecate ScalarValueToConstFetchRector - #8344

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-scalar-value-to-const-fetch
Aug 10, 2026
Merged

[deprecation] Deprecate ScalarValueToConstFetchRector#8344
TomasVotruba merged 1 commit into
mainfrom
deprecate-scalar-value-to-const-fetch

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecates ScalarValueToConstFetchRector.

The rule subscribes to every String_, Int_ and Float_ node in the project and compares the raw value. There is no context check, so the same value in an unrelated place is replaced too:

 final class SomeClass
 {
     public function run(array $items)
     {
-        $timeout = 10;
+        $timeout = \SomeClass::FOOBAR_INT;

         // unrelated, but replaced as well
-        return array_slice($items, 0, 10);
+        return array_slice($items, 0, \SomeClass::FOOBAR_INT);
     }
 }

The same happens with strings used as array keys, version numbers or messages. There is no way to configure a narrower target, so the rule cannot be made safe by configuration.

Use a custom rule scoped to the exact context (a specific argument, property or method) instead.

The rule now implements DeprecatedInterface and throws in refactor(). The ScalarValueToConstFetch value object is kept, so existing configs still load.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 10, 2026 21:11
@TomasVotruba
TomasVotruba merged commit 75db75e into main Aug 10, 2026
52 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-scalar-value-to-const-fetch branch August 10, 2026 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant