diff --git a/phpstan-baseline.php b/phpstan-baseline.php index 3cbe5a4732fc..a821168ce179 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -2148,7 +2148,7 @@ ]; $ignoreErrors[] = [ 'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#', - 'count' => 5, + 'count' => 3, 'path' => __DIR__ . '/system/HTTP/IncomingRequest.php', ]; $ignoreErrors[] = [ diff --git a/system/HTTP/IncomingRequest.php b/system/HTTP/IncomingRequest.php index 307a78d38b4a..e9dfef1f6e29 100755 --- a/system/HTTP/IncomingRequest.php +++ b/system/HTTP/IncomingRequest.php @@ -152,10 +152,12 @@ class IncomingRequest extends Request */ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?UserAgent $userAgent = null) { - if (empty($uri) || empty($userAgent)) { + if ($uri === null || $userAgent === null) { throw new InvalidArgumentException('You must supply the parameters: uri, userAgent.'); } + assert($uri instanceof SiteURI); + $this->populateHeaders(); if ( @@ -182,15 +184,22 @@ public function __construct($config, ?URI $uri = null, $body = 'php://input', ?U parent::__construct($config); - if ($uri instanceof SiteURI) { - $this->setPath($uri->getRoutePath()); - } else { - $this->setPath($uri->getPath()); - } - + $this->setPath($uri->getRoutePath()); $this->detectLocale($config); } + /** + * Retrieves the URI instance. + * + * @return SiteURI + */ + public function getUri() + { + assert($this->uri instanceof SiteURI); + + return $this->uri; + } + private function getPostMaxSize(): int { $postMaxSize = ini_get('post_max_size');