From ef3f1e9346314555b3fdfbf94380e93f2854518d Mon Sep 17 00:00:00 2001 From: delacry <45132928+delacry@users.noreply.github.com> Date: Sun, 27 Sep 2026 10:03:29 +0200 Subject: [PATCH] Document IndexOutOfBoundsException on List::removeAt() removeAt() declared @throws OutOfBoundsException (the SPL class), but every implementation raises Noctud\Collection\Exception\IndexOutOfBoundsException, which extends LogicException - so a catch written against the docblock never matched. Correct the declaration on ImmutableList and WritableList, regenerate the narrowed interfaces that copy it, drop the now unused imports, and fix the same mistake in the List API docs. --- docs/collection/api/list.md | 2 +- src/List/ImmutableList.php | 3 +-- src/List/MutableList.php | 3 +-- src/List/MutableTrackedList.php | 3 +-- src/List/WritableList.php | 3 +-- src/List/WritableTrackedList.php | 3 +-- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/docs/collection/api/list.md b/docs/collection/api/list.md index e5ba468..9f14294 100644 --- a/docs/collection/api/list.md +++ b/docs/collection/api/list.md @@ -107,7 +107,7 @@ Remove all occurrences of the element. Returns `$this`. ```php removeAt(int $index): MutableList ``` -Remove element at index. Throws `OutOfBoundsException`. Returns `$this`. +Remove element at index. Throws `IndexOutOfBoundsException` if out of bounds. Returns `$this`. ## ImmutableList Methods diff --git a/src/List/ImmutableList.php b/src/List/ImmutableList.php index ac478bf..d302621 100644 --- a/src/List/ImmutableList.php +++ b/src/List/ImmutableList.php @@ -14,7 +14,6 @@ use Noctud\Collection\Exception\IndexOutOfBoundsException; use Noctud\Collection\ImmutableCollection; use Noctud\Collection\Map\ImmutableMap; -use OutOfBoundsException; /** * @template E @@ -67,7 +66,7 @@ public function removeEvery(mixed $element): ImmutableList; * * @param int $index The index of the element to remove * @return ImmutableList A new list without the element at the specified index - * @throws OutOfBoundsException If the index is out of bounds + * @throws IndexOutOfBoundsException If the index is out of bounds */ #[NoDiscard] public function removeAt(int $index): ImmutableList; diff --git a/src/List/MutableList.php b/src/List/MutableList.php index bd000dc..940bc5a 100644 --- a/src/List/MutableList.php +++ b/src/List/MutableList.php @@ -13,7 +13,6 @@ use NoDiscard; use Noctud\Collection\Exception\IndexOutOfBoundsException; use Noctud\Collection\MutableCollection; -use OutOfBoundsException; /** * @template E @@ -226,7 +225,7 @@ public function removeEvery(mixed $element): MutableList; * * @param int $index The index of the element to remove * @return MutableList The list itself for chaining - * @throws OutOfBoundsException If the index is out of bounds + * @throws IndexOutOfBoundsException If the index is out of bounds */ public function removeAt(int $index): MutableList; diff --git a/src/List/MutableTrackedList.php b/src/List/MutableTrackedList.php index a42a9e5..8daa1d8 100644 --- a/src/List/MutableTrackedList.php +++ b/src/List/MutableTrackedList.php @@ -13,7 +13,6 @@ use Noctud\Collection\Exception\IndexOutOfBoundsException; use Noctud\Collection\MutableTrackedCollection; use Noctud\Collection\TrackedResult; -use OutOfBoundsException; /** * A mutable list that tracks whether the last mutation operation changed the list. @@ -206,7 +205,7 @@ public function removeEvery(mixed $element): MutableTrackedList&TrackedResult; * * @param int $index The index of the element to remove * @return MutableTrackedList&TrackedResult The list itself for chaining - * @throws OutOfBoundsException If the index is out of bounds + * @throws IndexOutOfBoundsException If the index is out of bounds */ public function removeAt(int $index): MutableTrackedList&TrackedResult; diff --git a/src/List/WritableList.php b/src/List/WritableList.php index f0d53fd..18a1312 100644 --- a/src/List/WritableList.php +++ b/src/List/WritableList.php @@ -14,7 +14,6 @@ use Noctud\Collection\Map\ImmutableMap; use Noctud\Collection\WritableCollection; use NoDiscard; -use OutOfBoundsException; /** * Writable list provides basic methods for read/write operations on a list. @@ -63,7 +62,7 @@ public function removeEvery(mixed $element): WritableList; * * @param int $index The index of the element to remove * @return WritableList The list itself for chaining - * @throws OutOfBoundsException If the index is out of bounds + * @throws IndexOutOfBoundsException If the index is out of bounds */ public function removeAt(int $index): WritableList; diff --git a/src/List/WritableTrackedList.php b/src/List/WritableTrackedList.php index ae9a24d..d294b29 100644 --- a/src/List/WritableTrackedList.php +++ b/src/List/WritableTrackedList.php @@ -13,7 +13,6 @@ use Noctud\Collection\Exception\IndexOutOfBoundsException; use Noctud\Collection\TrackedResult; use Noctud\Collection\WritableTrackedCollection; -use OutOfBoundsException; /** * A writable list that tracks whether the last mutation operation changed the list. @@ -49,7 +48,7 @@ public function removeEvery(mixed $element): WritableTrackedList&TrackedResult; * * @param int $index The index of the element to remove * @return WritableTrackedList&TrackedResult The list itself for chaining - * @throws OutOfBoundsException If the index is out of bounds + * @throws IndexOutOfBoundsException If the index is out of bounds */ public function removeAt(int $index): WritableTrackedList&TrackedResult;