namespace Friendica\Util;
+use Exception;
use Friendica\Core\Protocol;
use Friendica\Database\Database;
use Friendica\Database\DBA;
$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
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'])) {
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)
{
/** @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;
/**
$this->buffer = null;
$this->key = -1;
$this->value = null;
+
return $this;
}
{
// 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'];
function ($matches) use ($blocks) {
$return = $matches[0];
if (isset($blocks[intval($matches[1])])) {
- $return = $blocks[$matches[1]];
+ $return = $blocks[intval($matches[1])];
}
return $return;
},
*/
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));
}
/**
* @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)
{