diff options
author | ArthurHoaro <arthur@hoa.ro> | 2020-10-13 13:56:07 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-13 13:56:07 +0200 |
commit | 4a26974a4b36362d25d8a3a029eac539685c03f6 (patch) | |
tree | 4f34052788a08be1a30cb88c3339ae14e0b7c4da /application/bookmark/BookmarkArray.php | |
parent | 29c31b7ec6ca48ba37b7eb6da650931fd0cb7164 (diff) | |
parent | efb7d21b52eb033530e80e5e49d175e6e3b031f4 (diff) | |
download | Shaarli-4a26974a4b36362d25d8a3a029eac539685c03f6.tar.gz Shaarli-4a26974a4b36362d25d8a3a029eac539685c03f6.tar.zst Shaarli-4a26974a4b36362d25d8a3a029eac539685c03f6.zip |
Merge pull request #1583 from ArthurHoaro/feature/bookmark-strict-types
Add strict types for bookmarks management
Diffstat (limited to 'application/bookmark/BookmarkArray.php')
-rw-r--r-- | application/bookmark/BookmarkArray.php | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/application/bookmark/BookmarkArray.php b/application/bookmark/BookmarkArray.php index 3bd5eb20..67bb3b73 100644 --- a/application/bookmark/BookmarkArray.php +++ b/application/bookmark/BookmarkArray.php | |||
@@ -1,5 +1,7 @@ | |||
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | declare(strict_types=1); | ||
4 | |||
3 | namespace Shaarli\Bookmark; | 5 | namespace Shaarli\Bookmark; |
4 | 6 | ||
5 | use Shaarli\Bookmark\Exception\InvalidBookmarkException; | 7 | use Shaarli\Bookmark\Exception\InvalidBookmarkException; |
@@ -187,13 +189,13 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess | |||
187 | /** | 189 | /** |
188 | * Returns a bookmark offset in bookmarks array from its unique ID. | 190 | * Returns a bookmark offset in bookmarks array from its unique ID. |
189 | * | 191 | * |
190 | * @param int $id Persistent ID of a bookmark. | 192 | * @param int|null $id Persistent ID of a bookmark. |
191 | * | 193 | * |
192 | * @return int Real offset in local array, or null if doesn't exist. | 194 | * @return int Real offset in local array, or null if doesn't exist. |
193 | */ | 195 | */ |
194 | protected function getBookmarkOffset($id) | 196 | protected function getBookmarkOffset(?int $id): ?int |
195 | { | 197 | { |
196 | if (isset($this->ids[$id])) { | 198 | if ($id !== null && isset($this->ids[$id])) { |
197 | return $this->ids[$id]; | 199 | return $this->ids[$id]; |
198 | } | 200 | } |
199 | return null; | 201 | return null; |
@@ -205,7 +207,7 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess | |||
205 | * | 207 | * |
206 | * @return int next ID. | 208 | * @return int next ID. |
207 | */ | 209 | */ |
208 | public function getNextId() | 210 | public function getNextId(): int |
209 | { | 211 | { |
210 | if (!empty($this->ids)) { | 212 | if (!empty($this->ids)) { |
211 | return max(array_keys($this->ids)) + 1; | 213 | return max(array_keys($this->ids)) + 1; |
@@ -214,11 +216,11 @@ class BookmarkArray implements \Iterator, \Countable, \ArrayAccess | |||
214 | } | 216 | } |
215 | 217 | ||
216 | /** | 218 | /** |
217 | * @param $url | 219 | * @param string $url |
218 | * | 220 | * |
219 | * @return Bookmark|null | 221 | * @return Bookmark|null |
220 | */ | 222 | */ |
221 | public function getByUrl($url) | 223 | public function getByUrl(string $url): ?Bookmark |
222 | { | 224 | { |
223 | if (! empty($url) | 225 | if (! empty($url) |
224 | && isset($this->urls[$url]) | 226 | && isset($this->urls[$url]) |