From f832b58a3e18b7c142401d2d3e0ce505ea6c2a6b Mon Sep 17 00:00:00 2001 From: Sebastian Meyer Date: Mon, 22 Jan 2024 21:03:54 +0100 Subject: [PATCH] Make StrictList compatible with SplDoublyLinkedList --- src/DataStructures/StrictList.php | 7 +++---- src/DataStructures/StrictQueue.php | 5 ++--- src/DataStructures/StrictStack.php | 5 ++--- 3 files changed, 7 insertions(+), 10 deletions(-) diff --git a/src/DataStructures/StrictList.php b/src/DataStructures/StrictList.php index 14adceb..a700a13 100644 --- a/src/DataStructures/StrictList.php +++ b/src/DataStructures/StrictList.php @@ -279,12 +279,11 @@ class StrictList extends SplDoublyLinkedList /** * Create a type-sensitive, traversable list of items. * - * @param iterable $items Initial set of items * @param string[] $allowedTypes Allowed types of items (optional) * * @throws InvalidArgumentException */ - public function __construct(iterable $items = [], array $allowedTypes = []) + public function __construct(array $allowedTypes = []) { if (array_sum(array_map('is_string', $allowedTypes)) !== count($allowedTypes)) { throw new InvalidArgumentException( @@ -292,7 +291,6 @@ class StrictList extends SplDoublyLinkedList ); } $this->allowedTypes = $allowedTypes; - $this->append(...$items); } /** @@ -330,9 +328,10 @@ class StrictList extends SplDoublyLinkedList { /** @var string[] $allowedTypes */ $allowedTypes = $data['StrictList::allowedTypes']; + $this->__construct($allowedTypes); /** @var iterable $items */ $items = $data['SplDoublyLinkedList::dllist']; - $this->__construct($items, $allowedTypes); + $this->append(...$items); /** @var int $flags */ $flags = $data['SplDoublyLinkedList::flags']; $this->setIteratorMode($flags); diff --git a/src/DataStructures/StrictQueue.php b/src/DataStructures/StrictQueue.php index 10c9c14..7e668c7 100644 --- a/src/DataStructures/StrictQueue.php +++ b/src/DataStructures/StrictQueue.php @@ -89,12 +89,11 @@ class StrictQueue extends StrictList /** * Create a type-sensitive, traversable queue of items. * - * @param iterable $items Initial set of items * @param string[] $allowedTypes Allowed types of items (optional) */ - public function __construct(iterable $items = [], array $allowedTypes = []) + public function __construct(array $allowedTypes = []) { - parent::__construct($items, $allowedTypes); + parent::__construct($allowedTypes); $this->setIteratorMode(0); } } diff --git a/src/DataStructures/StrictStack.php b/src/DataStructures/StrictStack.php index 965af6d..aab6dd0 100644 --- a/src/DataStructures/StrictStack.php +++ b/src/DataStructures/StrictStack.php @@ -87,12 +87,11 @@ class StrictStack extends StrictList /** * Create a type-sensitive, traversable stack of items. * - * @param iterable $items Initial set of items * @param string[] $allowedTypes Allowed types of items (optional) */ - public function __construct(iterable $items = [], array $allowedTypes = []) + public function __construct(array $allowedTypes = []) { - parent::__construct($items, $allowedTypes); + parent::__construct($allowedTypes); $this->setIteratorMode(2); } }