From a8895b6491dc735a0f9539ed1f4f64c3da2fab61 Mon Sep 17 00:00:00 2001 From: David Grudl Date: Wed, 28 Jul 2021 13:13:46 +0200 Subject: [PATCH] used native PHP 8 functions --- src/Bridges/HttpDI/HttpExtension.php | 2 +- src/Http/Context.php | 2 +- src/Http/RequestFactory.php | 6 +++--- src/Http/Response.php | 2 +- src/Http/Url.php | 4 ++-- src/Http/UrlImmutable.php | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/Bridges/HttpDI/HttpExtension.php b/src/Bridges/HttpDI/HttpExtension.php index 10034fe2..70e6e08c 100644 --- a/src/Bridges/HttpDI/HttpExtension.php +++ b/src/Bridges/HttpDI/HttpExtension.php @@ -111,7 +111,7 @@ private function sendHeaders() continue; } $value = self::buildPolicy($config->$key); - if (strpos($value, "'nonce'")) { + if (str_contains($value, "'nonce'")) { $this->initialization->addBody('$cspNonce = base64_encode(random_bytes(16));'); $value = Nette\DI\ContainerBuilder::literal( 'str_replace(?, ? . $cspNonce, ?)', diff --git a/src/Http/Context.php b/src/Http/Context.php index d0f1ec68..dbc03b6f 100644 --- a/src/Http/Context.php +++ b/src/Http/Context.php @@ -50,7 +50,7 @@ public function isModified(string|int|\DateTimeInterface $lastModified = null, s } elseif ($ifNoneMatch !== null) { $etag = $this->response->getHeader('ETag'); - if ($etag === null || strpos(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag) === false) { + if ($etag === null || !str_contains(' ' . strtr($ifNoneMatch, ",\t", ' '), ' ' . $etag)) { return true; } else { diff --git a/src/Http/RequestFactory.php b/src/Http/RequestFactory.php index 6f69845c..01ee554a 100644 --- a/src/Http/RequestFactory.php +++ b/src/Http/RequestFactory.php @@ -286,9 +286,9 @@ private function useForwardedProxy(Url $url, &$remoteAddr, &$remoteHost): void if (isset($proxyParams['for'])) { $address = $proxyParams['for'][0]; - $remoteAddr = strpos($address, '[') === false - ? explode(':', $address)[0] // IPv4 - : substr($address, 1, strpos($address, ']') - 1); // IPv6 + $remoteAddr = str_contains($address, '[') + ? substr($address, 1, strpos($address, ']') - 1) // IPv6 + : explode(':', $address)[0]; // IPv4 } if (isset($proxyParams['host']) && count($proxyParams['host']) === 1) { diff --git a/src/Http/Response.php b/src/Http/Response.php index 41877c51..2a362d0c 100644 --- a/src/Http/Response.php +++ b/src/Http/Response.php @@ -225,7 +225,7 @@ public function __destruct() { if ( self::$fixIE - && strpos($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ') !== false + && str_contains($_SERVER['HTTP_USER_AGENT'] ?? '', 'MSIE ') && in_array($this->code, [400, 403, 404, 405, 406, 408, 409, 410, 500, 501, 505], true) && preg_match('#^text/html(?:;|$)#', (string) $this->getHeader('Content-Type')) ) { diff --git a/src/Http/Url.php b/src/Http/Url.php index 0c8d0809..49e859f1 100644 --- a/src/Http/Url.php +++ b/src/Http/Url.php @@ -178,7 +178,7 @@ public function getPort(): ?int public function setPath(string $path): static { $this->path = $path; - if ($this->host && substr($this->path, 0, 1) !== '/') { + if ($this->host && !str_starts_with($this->path, '/')) { $this->path = '/' . $this->path; } return $this; @@ -363,7 +363,7 @@ final public function export(): array */ private static function idnHostToUnicode(string $host): string { - if (strpos($host, '--') === false) { // host does not contain IDN + if (!str_contains($host, '--')) { // host does not contain IDN return $host; } if (function_exists('idn_to_utf8') && defined('INTL_IDNA_VARIANT_UTS46')) { diff --git a/src/Http/UrlImmutable.php b/src/Http/UrlImmutable.php index 9efce873..82ca0003 100644 --- a/src/Http/UrlImmutable.php +++ b/src/Http/UrlImmutable.php @@ -290,7 +290,7 @@ final public function export(): array protected function build(): void { - if ($this->host && substr($this->path, 0, 1) !== '/') { + if ($this->host && !str_starts_with($this->path, '/')) { $this->path = '/' . $this->path; }