Run Rector on your code to see what it can do for you:

 <?php
 
 final class Workload {
     // ...
 
     private function &getRef(int $index): int {
-        switch ($index) {
-            case 0:
-                return $this->monday;
-            case 1:
-                return $this->tuesday;
-            // ...
-            default:
-                throw new LogicException();
-        }
+        return match ($index) {
+            0 => $this->monday,
+            1 => $this->tuesday,
+            default => throw new LogicException(),
+        };
     }
 
     public function setAtIndex(int $index, int $value) {
PHP snippet to change

Applied Rules:

Not a change you expect?

Config  rector.php
Rector version: 367edb - released at 2026-01-28 17:10