diff --git a/composer.json b/composer.json index faec342..9b67380 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "friendsofphp/php-cs-fixer": "^3.95", "donatj/mddoc": "^0.10.1", "donatj/drop": "^1.1", - "phpstan/phpstan": "^1.12" + "phpstan/phpstan": "^2.1" }, "license": "MIT", "authors": [ diff --git a/src/ProxyAwareSchemer.php b/src/ProxyAwareSchemer.php index 3f93e7e..4966c7b 100644 --- a/src/ProxyAwareSchemer.php +++ b/src/ProxyAwareSchemer.php @@ -20,7 +20,7 @@ */ class ProxyAwareSchemer { - /** @var array */ + /** @var array */ private $server; public const HTTPS_EXPECTED_SERVER_VALUES = [ @@ -46,7 +46,7 @@ class ProxyAwareSchemer { private $proxyServerPortKeys; /** - * @param array $server Server array to inspect. Defaults to $_SERVER. + * @param array|null $server Server array to inspect. Defaults to $_SERVER. * * @param array|null $proxyServerHttpsKeyValues Map of $_SERVER keys to their expected https-positive value. * Defaults to ProxyAwareSchemer::HTTPS_EXPECTED_SERVER_VALUES @@ -105,6 +105,7 @@ public function withDetectedScheme( ) : UriInterface { foreach( $this->proxyServerHttpsKeyValues as $serverKey => $serverValue ) { if( isset($this->server[$serverKey]) + && is_scalar($this->server[$serverKey]) && strtolower((string)$this->server[$serverKey]) === $serverValue ) { $newUri = $uri->withScheme('https'); @@ -126,7 +127,7 @@ public function withDetectedScheme( */ public function withDetectedPort( UriInterface $uri, ?int $default = null ) : UriInterface { foreach( $this->proxyServerPortKeys as $portKey ) { - if( isset($this->server[$portKey]) ) { + if( isset($this->server[$portKey]) && is_numeric($this->server[$portKey]) ) { $port = (int)$this->server[$portKey]; if( $port > 0 && $port <= 65535 ) { return $uri->withPort($port);