From 477bec197750dd27efd57969653d81da32f7a2ed Mon Sep 17 00:00:00 2001 From: Philipp Date: Wed, 9 Nov 2022 23:16:12 +0100 Subject: [PATCH] Fix some PHP8.1 issues if possible --- src/App/Page.php | 2 +- src/Core/L10n.php | 6 +++--- src/Util/Network.php | 8 ++++---- src/Util/ReversedFileReader.php | 2 +- 4 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/App/Page.php b/src/App/Page.php index a6f46bdd85..0f14d9f6e6 100644 --- a/src/App/Page.php +++ b/src/App/Page.php @@ -130,7 +130,7 @@ class Page implements ArrayAccess * The return value will be casted to boolean if non-boolean was returned. * @since 5.0.0 */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return isset($this->page[$offset]); } diff --git a/src/Core/L10n.php b/src/Core/L10n.php index 0f879c4948..a74f18fa6b 100644 --- a/src/Core/L10n.php +++ b/src/Core/L10n.php @@ -188,10 +188,10 @@ class L10n { $lang_variable = $server['HTTP_ACCEPT_LANGUAGE'] ?? null; - $acceptedLanguages = preg_split('/,\s*/', $lang_variable); - - if (empty($acceptedLanguages)) { + if (empty($lang_variable)) { $acceptedLanguages = []; + } else { + $acceptedLanguages = preg_split('/,\s*/', $lang_variable); } // Add get as absolute quality accepted language (except this language isn't valid) diff --git a/src/Util/Network.php b/src/Util/Network.php index 508934db2c..5a06a0056e 100644 --- a/src/Util/Network.php +++ b/src/Util/Network.php @@ -485,11 +485,11 @@ class Network $get('host') . ($port ? ":$port" : ''); - return (strlen($scheme) ? $scheme . ':' : '') . - (strlen($authority) ? '//' . $authority : '') . + return (!empty($scheme) ? $scheme . ':' : '') . + (!empty($authority) ? '//' . $authority : '') . $get('path') . - (strlen($query) ? '?' . $query : '') . - (strlen($fragment) ? '#' . $fragment : ''); + (!empty($query) ? '?' . $query : '') . + (!empty($fragment) ? '#' . $fragment : ''); } /** diff --git a/src/Util/ReversedFileReader.php b/src/Util/ReversedFileReader.php index cda78ad0ab..2ef062152c 100644 --- a/src/Util/ReversedFileReader.php +++ b/src/Util/ReversedFileReader.php @@ -60,7 +60,7 @@ class ReversedFileReader implements \Iterator $this->fh = fopen($filename, 'r'); if (!$this->fh) { // this should use a custom exception. - throw \Exception("Unable to open $filename"); + throw new \Exception("Unable to open $filename"); } $this->filesize = filesize($filename); $this->pos = -1;