Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 6d01a03

Browse files
committed
minor #57610 [PsrHttpMessageBridge] Remove a redundant check in HttpFoundationFactory class (seriquynh)
This PR was merged into the 7.2 branch. Discussion ---------- [PsrHttpMessageBridge] Remove a redundant check in HttpFoundationFactory class | Q | A | ------------- | --- | Branch? | 7.2 | Bug fix? | no | New feature? | no | Deprecations? | no | Issues | N/A | License | MIT `HttpFoundationFactory::createRequest` method receives an implementation of `ServerRequestInterface` and it's `getUri` method must always return a `UriInterface` implementation. So, this check below is redundant. ```php <?php $uri = $psrRequest->getUri(); // absolutely is \Psr\Http\Message\UriInterface if ($uri instanceof UriInterface) { // redundant check // Do something } ``` ### My Concern I've checked Symfony roadmap/releases [here](https://symfony.com/releases). And I decided to create a PR to branch 6.4 because: - PsrHttpMessage is included in v6.4 (not in 5.4). - v6.4 is still maintained (v6.0, v6.1, v6.2 and v6.3 are "End of life" versions). - It is not a breaking/major change. Did I choose branch correctly? If not, please give me more references/posts about how to choose a right branch for a PR. Commits ------- 8e7e208149 Remove redundant check
2 parents 55891cd + e464593 commit 6d01a03

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

Factory/HttpFoundationFactory.php

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Psr\Http\Message\ServerRequestInterface;
1616
use Psr\Http\Message\StreamInterface;
1717
use Psr\Http\Message\UploadedFileInterface;
18-
use Psr\Http\Message\UriInterface;
1918
use Symfony\Bridge\PsrHttpMessage\HttpFoundationFactoryInterface;
2019
use Symfony\Component\HttpFoundation\Cookie;
2120
use Symfony\Component\HttpFoundation\Request;
@@ -40,19 +39,17 @@ public function createRequest(ServerRequestInterface $psrRequest, bool $streamed
4039
$server = [];
4140
$uri = $psrRequest->getUri();
4241

43-
if ($uri instanceof UriInterface) {
44-
$server['SERVER_NAME'] = $uri->getHost();
45-
$server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80);
46-
$server['REQUEST_URI'] = $uri->getPath();
47-
$server['QUERY_STRING'] = $uri->getQuery();
42+
$server['SERVER_NAME'] = $uri->getHost();
43+
$server['SERVER_PORT'] = $uri->getPort() ?: ('https' === $uri->getScheme() ? 443 : 80);
44+
$server['REQUEST_URI'] = $uri->getPath();
45+
$server['QUERY_STRING'] = $uri->getQuery();
4846

49-
if ('' !== $server['QUERY_STRING']) {
50-
$server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
51-
}
47+
if ('' !== $server['QUERY_STRING']) {
48+
$server['REQUEST_URI'] .= '?'.$server['QUERY_STRING'];
49+
}
5250

53-
if ('https' === $uri->getScheme()) {
54-
$server['HTTPS'] = 'on';
55-
}
51+
if ('https' === $uri->getScheme()) {
52+
$server['HTTPS'] = 'on';
5653
}
5754

5855
$server['REQUEST_METHOD'] = $psrRequest->getMethod();

0 commit comments

Comments
 (0)