X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fbookmark%2FBookmarkArray.php;h=67bb3b73d55fbcca2f68c3a651f76fb873f140a3;hb=330ac859fb13a3a15875f185a611bfaa6c5f5587;hp=d87d43b41ae41a3753aff732aa3989636728c4b4;hpb=3fb29fdda04ca86e04422d49b86cf646d53c4f9d;p=github%2Fshaarli%2FShaarli.git diff --git a/application/bookmark/BookmarkArray.php b/application/bookmark/BookmarkArray.php index d87d43b4..67bb3b73 100644 --- a/application/bookmark/BookmarkArray.php +++ b/application/bookmark/BookmarkArray.php @@ -1,5 +1,7 @@ ids[$id])) { + if ($id !== null && isset($this->ids[$id])) { return $this->ids[$id]; } return null; @@ -205,7 +207,7 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess * * @return int next ID. */ - public function getNextId() + public function getNextId(): int { if (!empty($this->ids)) { return max(array_keys($this->ids)) + 1; @@ -214,11 +216,11 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess } /** - * @param $url + * @param string $url * * @return Bookmark|null */ - public function getByUrl($url) + public function getByUrl(string $url): ?Bookmark { if (! empty($url) && isset($this->urls[$url]) @@ -234,16 +236,17 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess * * Also update the urls and ids mapping arrays. * - * @param string $order ASC|DESC + * @param string $order ASC|DESC + * @param bool $ignoreSticky If set to true, sticky bookmarks won't be first */ - public function reorder($order = 'DESC') + public function reorder(string $order = 'DESC', bool $ignoreSticky = false): void { $order = $order === 'ASC' ? -1 : 1; // Reorder array by dates. - usort($this->bookmarks, function ($a, $b) use ($order) { + usort($this->bookmarks, function ($a, $b) use ($order, $ignoreSticky) { /** @var $a Bookmark */ /** @var $b Bookmark */ - if ($a->isSticky() !== $b->isSticky()) { + if (false === $ignoreSticky && $a->isSticky() !== $b->isSticky()) { return $a->isSticky() ? -1 : 1; } return $a->getCreated() < $b->getCreated() ? 1 * $order : -1 * $order;