From ca3d98b9f5047e650f5a025836df687c266fb3a7 Mon Sep 17 00:00:00 2001 From: Art4 Date: Mon, 24 Feb 2025 15:15:26 +0000 Subject: [PATCH] Fix 11 errors --- src/Util/HTTPSignature.php | 13 ++++++------- src/Util/JsonLD.php | 7 ++----- src/Util/ReversedFileReader.php | 5 +++-- src/Util/Strings.php | 4 ++-- src/Util/Temporal.php | 2 +- src/Util/XML.php | 2 +- 6 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/Util/HTTPSignature.php b/src/Util/HTTPSignature.php index bb5d8c6b5a..058d83d62a 100644 --- a/src/Util/HTTPSignature.php +++ b/src/Util/HTTPSignature.php @@ -7,6 +7,7 @@ namespace Friendica\Util; +use Exception; use Friendica\Core\Protocol; use Friendica\Database\Database; use Friendica\Database\DBA; @@ -213,7 +214,7 @@ class HTTPSignature $headers = []; foreach ($matches as $match) { - $headers[$match[1]] = trim($match[2] ?: $match[3], '"'); + $headers[$match[1]] = trim((string) $match[2], '"'); } // if the header is encrypted, decrypt with (default) site private key and continue @@ -537,14 +538,12 @@ class HTTPSignature if (!empty($uid)) { $owner = User::getOwnerDataById($uid); - if (!$owner) { - return; - } } else { $owner = User::getSystemAccount(); - if (!$owner) { - return; - } + } + + if (!$owner) { + throw new Exception('Could not find owner for uid ' . $uid); } if (!empty($owner['uprvkey'])) { diff --git a/src/Util/JsonLD.php b/src/Util/JsonLD.php index 3301ca1b40..afca8d79ba 100644 --- a/src/Util/JsonLD.php +++ b/src/Util/JsonLD.php @@ -243,14 +243,11 @@ class JsonLD return json_decode(json_encode($json, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE)); } + /** * Fetches an element array from a JSON array * - * @param $array - * @param $element - * @param $key - * - * @return array fetched element + * @return array|null fetched element or null */ public static function fetchElementArray($array, $element, $key = null, $type = null, $type_value = null) { diff --git a/src/Util/ReversedFileReader.php b/src/Util/ReversedFileReader.php index 779933cbc6..57800ab561 100644 --- a/src/Util/ReversedFileReader.php +++ b/src/Util/ReversedFileReader.php @@ -26,13 +26,13 @@ class ReversedFileReader implements \Iterator /** @var int */ private $pos = -1; - /** @var array */ + /** @var array|null */ private $buffer = null; /** @var int */ private $key = -1; - /** @var string */ + /** @var string|null */ private $value = null; /** @@ -53,6 +53,7 @@ class ReversedFileReader implements \Iterator $this->buffer = null; $this->key = -1; $this->value = null; + return $this; } diff --git a/src/Util/Strings.php b/src/Util/Strings.php index efa0994ec3..9dbf361761 100644 --- a/src/Util/Strings.php +++ b/src/Util/Strings.php @@ -209,7 +209,7 @@ class Strings { // If this method is called for an infinite (== unlimited) amount of bytes: if ($bytes == INF) { - return INF; + return 'INF'; } $units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; @@ -509,7 +509,7 @@ class Strings function ($matches) use ($blocks) { $return = $matches[0]; if (isset($blocks[intval($matches[1])])) { - $return = $blocks[$matches[1]]; + $return = $blocks[intval($matches[1])]; } return $return; }, diff --git a/src/Util/Temporal.php b/src/Util/Temporal.php index 3e9ea157d5..cc9baa53a9 100644 --- a/src/Util/Temporal.php +++ b/src/Util/Temporal.php @@ -405,7 +405,7 @@ class Temporal */ public static function getDaysInMonth(int $y, int $m): int { - return date('t', mktime(0, 0, 0, $m, 1, $y)); + return (int) date('t', mktime(0, 0, 0, $m, 1, $y)); } /** diff --git a/src/Util/XML.php b/src/Util/XML.php index cf5689c361..4c099fb78e 100644 --- a/src/Util/XML.php +++ b/src/Util/XML.php @@ -184,7 +184,7 @@ class XML * @param integer $recursion_depth recursion counter for internal use - default 0 * internal use, recursion counter * - * @return array | string The array from the xml element or the string + * @return array|string|null The array from the xml element or the string */ public static function elementToArray($xml_element, int &$recursion_depth = 0) { -- 2.39.5