Skip to content

[CodeQuality] Deprecate UnusedForeachValueToArrayKeysRector - #8278

Merged
TomasVotruba merged 1 commit into
mainfrom
deprecate-unused-foreach-value-to-array-keys
Aug 3, 2026
Merged

[CodeQuality] Deprecate UnusedForeachValueToArrayKeysRector#8278
TomasVotruba merged 1 commit into
mainfrom
deprecate-unused-foreach-value-to-array-keys

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Deprecates UnusedForeachValueToArrayKeysRector.

The rule is opinionated: wrapping the iterated expression in array_keys() makes the foreach harder to read, and harder to extend once the value is needed again - then the whole line has to be reverted back.

 class SomeClass
 {
     public function run()
     {
         $items = [];
-        foreach ($values as $key => $value) {
+        foreach (array_keys($values) as $key) {
             $items[$key] = null;
         }
     }
 }

Also removed from the code quality level.

@TomasVotruba
TomasVotruba merged commit 72f8056 into main Aug 3, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the deprecate-unused-foreach-value-to-array-keys branch August 3, 2026 15:33
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