Resolve PHP 8.1 deprecations (#1866)
Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com> Co-authored-by: ArthurHoaro <arthur@hoa.ro>
This commit is contained in:
parent
221a2534b2
commit
dbd99f310f
9 changed files with 31 additions and 26 deletions
|
@ -61,6 +61,7 @@ function smallHash($text)
|
|||
*/
|
||||
function startsWith($haystack, $needle, $case = true)
|
||||
{
|
||||
$needle = $needle ?? '';
|
||||
if ($case) {
|
||||
return (strcmp(substr($haystack, 0, strlen($needle)), $needle) === 0);
|
||||
}
|
||||
|
@ -180,7 +181,7 @@ function generateLocation($referer, $host, $loopTerms = [])
|
|||
$host = substr($host, 0, $pos);
|
||||
}
|
||||
|
||||
$refererHost = parse_url($referer, PHP_URL_HOST);
|
||||
$refererHost = parse_url($referer, PHP_URL_HOST) ?? '';
|
||||
if (!empty($referer) && (strpos($refererHost, $host) !== false || startsWith('?', $refererHost))) {
|
||||
$finalReferer = $referer;
|
||||
}
|
||||
|
@ -292,7 +293,7 @@ function generate_api_secret($username, $salt)
|
|||
*/
|
||||
function normalize_spaces($string)
|
||||
{
|
||||
return preg_replace('/\s{2,}/', ' ', trim($string));
|
||||
return preg_replace('/\s{2,}/', ' ', trim($string ?? ''));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -30,7 +30,7 @@ public function getHistory($request, $response)
|
|||
$history = $this->history->getHistory();
|
||||
|
||||
// Return history operations from the {offset}th, starting from {since}.
|
||||
$since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since'));
|
||||
$since = \DateTime::createFromFormat(\DateTime::ATOM, $request->getParam('since', ''));
|
||||
$offset = $request->getParam('offset');
|
||||
if (empty($offset)) {
|
||||
$offset = 0;
|
||||
|
|
|
@ -57,7 +57,7 @@ public function __construct()
|
|||
*
|
||||
* @return int Number of bookmarks
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->bookmarks);
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ public function count()
|
|||
*
|
||||
* @throws InvalidBookmarkException
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
if (
|
||||
! $value instanceof Bookmark
|
||||
|
@ -106,7 +106,7 @@ public function offsetSet($offset, $value)
|
|||
*
|
||||
* @return bool true if it exists, false otherwise
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return array_key_exists($this->getBookmarkOffset($offset), $this->bookmarks);
|
||||
}
|
||||
|
@ -116,7 +116,7 @@ public function offsetExists($offset)
|
|||
*
|
||||
* @param int $offset Bookmark ID
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
$realOffset = $this->getBookmarkOffset($offset);
|
||||
$url = $this->bookmarks[$realOffset]->getUrl();
|
||||
|
@ -132,7 +132,7 @@ public function offsetUnset($offset)
|
|||
*
|
||||
* @return Bookmark|null The Bookmark if found, null otherwise
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
public function offsetGet($offset): ?Bookmark
|
||||
{
|
||||
$realOffset = $this->getBookmarkOffset($offset);
|
||||
return isset($this->bookmarks[$realOffset]) ? $this->bookmarks[$realOffset] : null;
|
||||
|
@ -143,7 +143,7 @@ public function offsetGet($offset)
|
|||
*
|
||||
* @return Bookmark corresponding to the current position
|
||||
*/
|
||||
public function current()
|
||||
public function current(): Bookmark
|
||||
{
|
||||
return $this[$this->keys[$this->position]];
|
||||
}
|
||||
|
@ -153,7 +153,7 @@ public function current()
|
|||
*
|
||||
* @return int Bookmark ID corresponding to the current position
|
||||
*/
|
||||
public function key()
|
||||
public function key(): int
|
||||
{
|
||||
return $this->keys[$this->position];
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ public function key()
|
|||
/**
|
||||
* Iterator - Moves forward to next element
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
++$this->position;
|
||||
}
|
||||
|
@ -171,7 +171,7 @@ public function next()
|
|||
*
|
||||
* Entries are sorted by date (latest first)
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->keys = array_keys($this->ids);
|
||||
$this->position = 0;
|
||||
|
@ -182,7 +182,7 @@ public function rewind()
|
|||
*
|
||||
* @return bool true if the current Bookmark ID exists, false otherwise
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return isset($this->keys[$this->position]);
|
||||
}
|
||||
|
|
|
@ -219,7 +219,7 @@ function tags_str2array(?string $tags, string $separator): array
|
|||
// For whitespaces, we use the special \s regex character
|
||||
$separator = $separator === ' ' ? '\s' : $separator;
|
||||
|
||||
return preg_split('/\s*' . $separator . '+\s*/', trim($tags) ?? '', -1, PREG_SPLIT_NO_EMPTY);
|
||||
return preg_split('/\s*' . $separator . '+\s*/', trim($tags ?? ''), -1, PREG_SPLIT_NO_EMPTY);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -120,7 +120,7 @@ protected function formatRealUrl($bookmark)
|
|||
$prefix = rtrim($this->contextData['base_path'], '/') . '/';
|
||||
}
|
||||
|
||||
return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl(), '/'));
|
||||
return escape($prefix ?? '') . escape(ltrim($bookmark->getUrl() ?? '', '/'));
|
||||
}
|
||||
|
||||
return escape($bookmark->getUrl());
|
||||
|
|
|
@ -45,7 +45,7 @@ public function index(Request $request, Response $response): Response
|
|||
*/
|
||||
public function ajaxUpdate(Request $request, Response $response, array $args): Response
|
||||
{
|
||||
$id = $args['id'] ?? null;
|
||||
$id = $args['id'] ?? '';
|
||||
|
||||
if (false === ctype_digit($id)) {
|
||||
return $response->withStatus(400);
|
||||
|
|
|
@ -238,7 +238,7 @@ public static function checkResourcePermissions(ConfigManager $conf, bool $minim
|
|||
$conf->get('resource.update_check'),
|
||||
] as $path
|
||||
) {
|
||||
if (!is_file(realpath($path))) {
|
||||
if (!is_string($path) || !is_file(realpath($path))) {
|
||||
# the file may not exist yet
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ class Url
|
|||
*/
|
||||
public function __construct($url)
|
||||
{
|
||||
$url = $url ?? '';
|
||||
$url = self::cleanupUnparsedUrl(trim($url));
|
||||
$this->parts = parse_url($url);
|
||||
|
||||
|
|
|
@ -116,7 +116,7 @@ public function __construct(
|
|||
/**
|
||||
* Countable - Counts elements of an object
|
||||
*/
|
||||
public function count()
|
||||
public function count(): int
|
||||
{
|
||||
return count($this->links);
|
||||
}
|
||||
|
@ -124,7 +124,7 @@ public function count()
|
|||
/**
|
||||
* ArrayAccess - Assigns a value to the specified offset
|
||||
*/
|
||||
public function offsetSet($offset, $value)
|
||||
public function offsetSet($offset, $value): void
|
||||
{
|
||||
// TODO: use exceptions instead of "die"
|
||||
if (!$this->loggedIn) {
|
||||
|
@ -155,7 +155,7 @@ public function offsetSet($offset, $value)
|
|||
/**
|
||||
* ArrayAccess - Whether or not an offset exists
|
||||
*/
|
||||
public function offsetExists($offset)
|
||||
public function offsetExists($offset): bool
|
||||
{
|
||||
return array_key_exists($this->getLinkOffset($offset), $this->links);
|
||||
}
|
||||
|
@ -163,7 +163,7 @@ public function offsetExists($offset)
|
|||
/**
|
||||
* ArrayAccess - Unsets an offset
|
||||
*/
|
||||
public function offsetUnset($offset)
|
||||
public function offsetUnset($offset): void
|
||||
{
|
||||
if (!$this->loggedIn) {
|
||||
// TODO: raise an exception
|
||||
|
@ -179,7 +179,7 @@ public function offsetUnset($offset)
|
|||
/**
|
||||
* ArrayAccess - Returns the value at specified offset
|
||||
*/
|
||||
public function offsetGet($offset)
|
||||
public function offsetGet($offset): ?array
|
||||
{
|
||||
$realOffset = $this->getLinkOffset($offset);
|
||||
return isset($this->links[$realOffset]) ? $this->links[$realOffset] : null;
|
||||
|
@ -188,14 +188,17 @@ public function offsetGet($offset)
|
|||
/**
|
||||
* Iterator - Returns the current element
|
||||
*/
|
||||
public function current()
|
||||
public function current(): array
|
||||
{
|
||||
return $this[$this->keys[$this->position]];
|
||||
}
|
||||
|
||||
/**
|
||||
* Iterator - Returns the key of the current element
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function key()
|
||||
{
|
||||
return $this->keys[$this->position];
|
||||
|
@ -204,7 +207,7 @@ public function key()
|
|||
/**
|
||||
* Iterator - Moves forward to next element
|
||||
*/
|
||||
public function next()
|
||||
public function next(): void
|
||||
{
|
||||
++$this->position;
|
||||
}
|
||||
|
@ -214,7 +217,7 @@ public function next()
|
|||
*
|
||||
* Entries are sorted by date (latest first)
|
||||
*/
|
||||
public function rewind()
|
||||
public function rewind(): void
|
||||
{
|
||||
$this->keys = array_keys($this->ids);
|
||||
$this->position = 0;
|
||||
|
@ -223,7 +226,7 @@ public function rewind()
|
|||
/**
|
||||
* Iterator - Checks if current position is valid
|
||||
*/
|
||||
public function valid()
|
||||
public function valid(): bool
|
||||
{
|
||||
return isset($this->keys[$this->position]);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue