From 9e8317d4d2413a0e602a7209591351a22a526d09 Mon Sep 17 00:00:00 2001 From: Brad Dutton Date: Fri, 13 May 2022 18:44:19 -0700 Subject: [PATCH] more php 8.1 updates --- modules/gallery/helpers/gallery_block.php | 2 +- modules/gallery/helpers/message.php | 1 + modules/gallery/libraries/MY_ORM.php | 5 ++-- modules/tag/helpers/tag_task.php | 4 +-- system/core/Event.php | 2 +- system/helpers/html.php | 3 ++ system/helpers/url.php | 33 +++++++++++++-------- system/libraries/Database_Mysqli_Result.php | 12 ++------ system/libraries/Database_Result.php | 18 +++++------ system/libraries/ORM_Iterator.php | 19 ++++++------ system/libraries/Router.php | 4 +-- 11 files changed, 54 insertions(+), 49 deletions(-) diff --git a/modules/gallery/helpers/gallery_block.php b/modules/gallery/helpers/gallery_block.php index 5ac4d74d..32b43295 100644 --- a/modules/gallery/helpers/gallery_block.php +++ b/modules/gallery/helpers/gallery_block.php @@ -142,4 +142,4 @@ class gallery_block_Core { $group->submit("sidebar")->value(t("Add to sidebar")); return $form; } -} \ No newline at end of file +} diff --git a/modules/gallery/helpers/message.php b/modules/gallery/helpers/message.php index a78b21d6..977a4716 100644 --- a/modules/gallery/helpers/message.php +++ b/modules/gallery/helpers/message.php @@ -63,6 +63,7 @@ class message_Core { private static function _add($msg, $severity) { $session = Session::instance(); $status = $session->get("messages"); + if (!is_array($status)) $status = []; $status[] = array($msg, $severity); $session->set("messages", $status); } diff --git a/modules/gallery/libraries/MY_ORM.php b/modules/gallery/libraries/MY_ORM.php index 6e538d54..13d51bd5 100644 --- a/modules/gallery/libraries/MY_ORM.php +++ b/modules/gallery/libraries/MY_ORM.php @@ -42,11 +42,12 @@ class ORM_Iterator extends ORM_Iterator_Core { /** * Cache the result row */ - public function current() { + public function current(): mixed + { $row = parent::current(); if (is_object($row)) { model_cache::set($row); } return $row; } -} \ No newline at end of file +} diff --git a/modules/tag/helpers/tag_task.php b/modules/tag/helpers/tag_task.php index af9f2f15..5388b14a 100644 --- a/modules/tag/helpers/tag_task.php +++ b/modules/tag/helpers/tag_task.php @@ -71,7 +71,7 @@ class tag_task_Core { $completed++; $tags->next(); } - $task->percent_complete = $completed / $total * 100; + $task->percent_complete = $total ? $completed / $total * 100 : 100; $task->set("completed", $completed); $task->set("last_tag_id", $last_tag_id); } @@ -94,4 +94,4 @@ class tag_task_Core { $task->log($errors); } } -} \ No newline at end of file +} diff --git a/system/core/Event.php b/system/core/Event.php index ab839f43..8b4b0cf2 100644 --- a/system/core/Event.php +++ b/system/core/Event.php @@ -228,4 +228,4 @@ abstract class Event_Core { return isset(Event::$has_run[$name]); } -} // End Event \ No newline at end of file +} // End Event diff --git a/system/helpers/html.php b/system/helpers/html.php index c16031d2..563b0209 100644 --- a/system/helpers/html.php +++ b/system/helpers/html.php @@ -21,6 +21,8 @@ class html_Core { */ public static function chars($str, $double_encode = TRUE) { + if (is_null($str)) return ''; + // Return HTML entities using the Kohana charset return htmlspecialchars($str, ENT_QUOTES, Kohana::CHARSET, $double_encode); } @@ -355,6 +357,7 @@ class html_Core { $compiled = ''; foreach ($attrs as $key => $val) { + if (is_null($val)) $val = ''; $compiled .= ' '.$key.'="'.htmlspecialchars($val, ENT_QUOTES, Kohana::CHARSET).'"'; } diff --git a/system/helpers/url.php b/system/helpers/url.php index 9e601d37..e0c4f174 100644 --- a/system/helpers/url.php +++ b/system/helpers/url.php @@ -97,22 +97,29 @@ class url_Core { */ public static function site($uri = '', $protocol = FALSE) { - if ($path = trim(parse_url($uri, PHP_URL_PATH), '/')) - { - // Add path suffix - $path .= Kohana::config('core.url_suffix'); - } + $path = ''; + $query = ''; + $fragment = ''; - if ($query = parse_url($uri, PHP_URL_QUERY)) + if ($uri) { - // ?query=string - $query = '?'.$query; - } + if ($path = trim(parse_url($uri, PHP_URL_PATH), '/')) + { + // Add path suffix + $path .= Kohana::config('core.url_suffix'); + } - if ($fragment = parse_url($uri, PHP_URL_FRAGMENT)) - { - // #fragment - $fragment = '#'.$fragment; + if ($query = parse_url($uri, PHP_URL_QUERY)) + { + // ?query=string + $query = '?'.$query; + } + + if ($fragment = parse_url($uri, PHP_URL_FRAGMENT)) + { + // #fragment + $fragment = '#'.$fragment; + } } // Concat the URL diff --git a/system/libraries/Database_Mysqli_Result.php b/system/libraries/Database_Mysqli_Result.php index f8b7b588..1d261626 100644 --- a/system/libraries/Database_Mysqli_Result.php +++ b/system/libraries/Database_Mysqli_Result.php @@ -129,25 +129,19 @@ class Database_Mysqli_Result_Core extends Database_Result { /** * SeekableIterator: seek */ - public function seek($offset) + public function seek($offset): void { if ($this->offsetExists($offset) AND $this->result->data_seek($offset)) { // Set the current row to the offset $this->current_row = $offset; - - return TRUE; - } - else - { - return FALSE; } } /** * Iterator: current */ - public function current() + public function current(): mixed { if ($this->current_row !== $this->internal_row AND ! $this->seek($this->current_row)) return NULL; @@ -172,4 +166,4 @@ class Database_Mysqli_Result_Core extends Database_Result { } } -} // End Database_MySQLi_Result \ No newline at end of file +} // End Database_MySQLi_Result diff --git a/system/libraries/Database_Result.php b/system/libraries/Database_Result.php index 9ba2dd7a..7d0aa1ce 100644 --- a/system/libraries/Database_Result.php +++ b/system/libraries/Database_Result.php @@ -80,7 +80,7 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * Countable: count */ - public function count() + public function count(): int { return $this->total_rows; } @@ -88,7 +88,7 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * ArrayAccess: offsetExists */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return ($offset >= 0 AND $offset < $this->total_rows); } @@ -96,7 +96,7 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * ArrayAccess: offsetGet */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { if ( ! $this->seek($offset)) return NULL; @@ -109,7 +109,7 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter * * @throws Kohana_Database_Exception */ - final public function offsetSet($offset, $value) + final public function offsetSet($offset, $value): void { throw new Kohana_Exception('Database results are read-only'); } @@ -128,7 +128,7 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * Iterator: key */ - public function key() + public function key(): mixed { return $this->current_row; } @@ -136,10 +136,9 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * Iterator: next */ - public function next() + public function next(): void { ++$this->current_row; - return $this; } /** @@ -154,16 +153,15 @@ abstract class Database_Result_Core implements Countable, Iterator, SeekableIter /** * Iterator: rewind */ - public function rewind() + public function rewind(): void { $this->current_row = 0; - return $this; } /** * Iterator: valid */ - public function valid() + public function valid(): bool { return $this->offsetExists($this->current_row); } diff --git a/system/libraries/ORM_Iterator.php b/system/libraries/ORM_Iterator.php index 436f052a..97389479 100644 --- a/system/libraries/ORM_Iterator.php +++ b/system/libraries/ORM_Iterator.php @@ -168,7 +168,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * Countable: count */ - public function count() + public function count(): int { return $this->result->count(); } @@ -176,7 +176,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * Iterator: current */ - public function current() + public function current(): mixed { if ($row = $this->result->current()) { @@ -192,7 +192,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * Iterator: key */ - public function key() + public function key(): mixed { return $this->result->key(); } @@ -200,15 +200,15 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * Iterator: next */ - public function next() + public function next(): void { - return $this->result->next(); + $this->result->next(); } /** * Iterator: rewind */ - public function rewind() + public function rewind(): void { $this->result->rewind(); } @@ -216,7 +216,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * Iterator: valid */ - public function valid() + public function valid(): bool { return $this->result->valid(); } @@ -224,7 +224,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * ArrayAccess: offsetExists */ - public function offsetExists($offset) + public function offsetExists($offset): bool { return $this->result->offsetExists($offset); } @@ -232,6 +232,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { /** * ArrayAccess: offsetGet */ + #[\ReturnTypeWillChange] public function offsetGet($offset) { if ($this->result->offsetExists($offset)) @@ -248,7 +249,7 @@ class ORM_Iterator_Core implements Iterator, ArrayAccess, Countable { * * @throws Kohana_Database_Exception */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { throw new Kohana_Database_Exception('database.result_read_only'); } diff --git a/system/libraries/Router.php b/system/libraries/Router.php index c36121df..3046e23d 100644 --- a/system/libraries/Router.php +++ b/system/libraries/Router.php @@ -282,7 +282,7 @@ class Router_Core { // Trim slashes $key = trim($key, '/'); - $val = trim($val, '/'); + $val = !empty($val) ? trim($val, '/') : ''; if (preg_match('#^'.$key.'$#u', $uri)) { @@ -312,4 +312,4 @@ class Router_Core { return trim($routed_uri, '/'); } -} // End Router \ No newline at end of file +} // End Router