|
8 | 8 |
|
9 | 9 | /** |
10 | 10 | * Represents an HTTP request received by the server. This class is immutable. |
| 11 | + * |
| 12 | + * @psalm-immutable |
11 | 13 | */ |
12 | 14 | final class Request extends Message |
13 | 15 | { |
@@ -332,6 +334,7 @@ public function withQuery(array $query): Request |
332 | 334 |
|
333 | 335 | // Ensure that we get a value for getQuery() that's consistent with the query string, and whose scalar values |
334 | 336 | // have all been converted to strings, to get a result similar to what we'd get with an incoming HTTP request. |
| 337 | + /** @psalm-suppress ImpureFunctionCall */ |
335 | 338 | parse_str($that->queryString, $that->query); |
336 | 339 |
|
337 | 340 | $that->requestUri = $that->path; |
@@ -378,6 +381,7 @@ public function withPost(array $post): Request |
378 | 381 |
|
379 | 382 | // Ensure that we get a value for getQuery() that's consistent with the query string, and whose scalar values |
380 | 383 | // have all been converted to strings, to get a result similar to what we'd get with an incoming HTTP request. |
| 384 | + /** @psalm-suppress ImpureFunctionCall */ |
381 | 385 | parse_str(http_build_query($post), $that->post); |
382 | 386 |
|
383 | 387 | if (! $that->isContentType('multipart/form-data')) { |
@@ -540,6 +544,8 @@ public function withCookies(array $cookies): Request |
540 | 544 | $that = clone $this; |
541 | 545 |
|
542 | 546 | $query = http_build_query($cookies); |
| 547 | + |
| 548 | + /** @psalm-suppress ImpureFunctionCall */ |
543 | 549 | parse_str($query, $that->cookies); |
544 | 550 |
|
545 | 551 | if ($cookies) { |
@@ -855,7 +861,9 @@ public function withPath(string $path): Request |
855 | 861 | $that = clone $this; |
856 | 862 | $that->path = $path; |
857 | 863 |
|
858 | | - return $that->updateRequestUri(); |
| 864 | + $that->requestUri = $that->recomputeRequestUri(); |
| 865 | + |
| 866 | + return $that; |
859 | 867 | } |
860 | 868 |
|
861 | 869 | /** |
@@ -890,25 +898,27 @@ public function withQueryString(string $queryString): Request |
890 | 898 | $that = clone $this; |
891 | 899 |
|
892 | 900 | $that->queryString = $queryString; |
| 901 | + |
| 902 | + /** @psalm-suppress ImpureFunctionCall */ |
893 | 903 | parse_str($that->queryString, $that->query); |
894 | 904 |
|
895 | | - return $that->updateRequestUri(); |
| 905 | + $that->requestUri = $that->recomputeRequestUri(); |
| 906 | + |
| 907 | + return $that; |
896 | 908 | } |
897 | 909 |
|
898 | 910 | /** |
899 | | - * Updates the request URI from the values of path and query string. |
900 | | - * |
901 | | - * @return static This request. |
| 911 | + * Recomputes the request URI from the values of path and query string. |
902 | 912 | */ |
903 | | - private function updateRequestUri() : Request |
| 913 | + private function recomputeRequestUri(): string |
904 | 914 | { |
905 | | - $this->requestUri = $this->path; |
| 915 | + $requestUri = $this->path; |
906 | 916 |
|
907 | 917 | if ($this->queryString !== '') { |
908 | | - $this->requestUri .= '?' . $this->queryString; |
| 918 | + $requestUri .= '?' . $this->queryString; |
909 | 919 | } |
910 | 920 |
|
911 | | - return $this; |
| 921 | + return $requestUri; |
912 | 922 | } |
913 | 923 |
|
914 | 924 | /** |
@@ -953,6 +963,7 @@ public function withRequestUri(string $requestUri): Request |
953 | 963 | if ($that->queryString === '') { |
954 | 964 | $that->query = []; |
955 | 965 | } else { |
| 966 | + /** @psalm-suppress ImpureFunctionCall */ |
956 | 967 | parse_str($that->queryString, $that->query); |
957 | 968 | } |
958 | 969 | } |
@@ -1037,21 +1048,20 @@ public function withUrl(string $url): Request |
1037 | 1048 |
|
1038 | 1049 | if (isset($components['query'])) { |
1039 | 1050 | $that->queryString = $components['query']; |
| 1051 | + /** @psalm-suppress ImpureFunctionCall */ |
1040 | 1052 | parse_str($that->queryString, $that->query); |
1041 | 1053 | $requestUri .= '?' . $that->queryString; |
1042 | 1054 | } else { |
1043 | 1055 | $that->queryString = ''; |
1044 | 1056 | $that->query = []; |
1045 | 1057 | } |
1046 | 1058 |
|
1047 | | - $that = $that->withHeader('Host', $hostHeader); |
1048 | | - |
1049 | 1059 | $that->host = $host; |
1050 | 1060 | $that->port = $port; |
1051 | 1061 | $that->isSecure = $isSecure; |
1052 | 1062 | $that->requestUri = $requestUri; |
1053 | 1063 |
|
1054 | | - return $that; |
| 1064 | + return $that->withHeader('Host', $hostHeader); |
1055 | 1065 | } |
1056 | 1066 |
|
1057 | 1067 | /** |
|
0 commit comments