aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/bookmark/BookmarkArray.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-10-02 17:50:59 +0200
committerArthurHoaro <arthur@hoa.ro>2020-10-13 13:50:11 +0200
commitefb7d21b52eb033530e80e5e49d175e6e3b031f4 (patch)
tree4f34052788a08be1a30cb88c3339ae14e0b7c4da /application/bookmark/BookmarkArray.php
parent29c31b7ec6ca48ba37b7eb6da650931fd0cb7164 (diff)
downloadShaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.tar.gz
Shaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.tar.zst
Shaarli-efb7d21b52eb033530e80e5e49d175e6e3b031f4.zip
Add strict types for bookmarks management
Parameters typing and using strict types overall increase the codebase quality by enforcing the a given parameter will have the expected type. It also removes the need to unnecessary unit tests checking methods behavior with invalid input.
Diffstat (limited to 'application/bookmark/BookmarkArray.php')
-rw-r--r--application/bookmark/BookmarkArray.php14
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
3declare(strict_types=1);
4
3namespace Shaarli\Bookmark; 5namespace Shaarli\Bookmark;
4 6
5use Shaarli\Bookmark\Exception\InvalidBookmarkException; 7use 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])