Browse Source

Only apply new logic if exploded into two parts

Jamison Bryant 1 year ago
parent
commit
4a1d7532fc
1 changed files with 10 additions and 12 deletions
  1. 10 12
      src/Http/ServerRequest.php

+ 10 - 12
src/Http/ServerRequest.php

@@ -485,19 +485,17 @@ class ServerRequest implements ServerRequestInterface
         } elseif (str_starts_with($name, 'get')) {
             // e.g. getCookieAsInt(), getQueryAsBool()
             $parts = explode('As', $name);
-            if (count($parts) !== 2) {
-                return $this->$name(...$params);
-            }
-
-            [$methodName, $type] = $parts;
 
-            return match ($methodName) {
-                'getCookie' => $this->asType($type, $this->cookies, ...$params),
-                'getQuery' => $this->asType($type, $this->query, ...$params),
-                'getParam' => $this->asType($type, $this->params, ...$params),
-                'getData' => $this->asType($type, $this->data ?? [], ...$params),
-                default => throw new BadMethodCallException(sprintf('Unable to convert request data to %s.', $type)),
-            };
+            if (count($parts) === 2) {
+                [$methodName, $type] = $parts;
+                return match ($methodName) {
+                    'getCookie' => $this->asType($type, $this->cookies, ...$params),
+                    'getQuery' => $this->asType($type, $this->query, ...$params),
+                    'getParam' => $this->asType($type, $this->params, ...$params),
+                    'getData' => $this->asType($type, $this->data ?? [], ...$params),
+                    default => throw new BadMethodCallException(sprintf('Unable to convert request data to %s.', $type)),
+                };
+            }
         }
 
         throw new BadMethodCallException(sprintf('Method `%s()` does not exist.', $name));