From 050057a70811bc9f60ef31cfebac54bb84faa855 Mon Sep 17 00:00:00 2001 From: Mark <14284867+xHeaven@users.noreply.github.com> Date: Sun, 29 Dec 2024 07:07:26 +0100 Subject: [PATCH] Use iterable type instead of unnecessary checks --- src/Comparable.php | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/Comparable.php b/src/Comparable.php index c655912..116178a 100644 --- a/src/Comparable.php +++ b/src/Comparable.php @@ -20,21 +20,9 @@ trait Comparable return ! $this->is($enum); } - public function in(array|object $enums): bool + public function in(iterable $enums): bool { - $iterator = $enums; - - if (! is_array($enums)) { - if ($enums instanceof Iterator) { - $iterator = $enums; - } elseif ($enums instanceof IteratorAggregate) { - $iterator = $enums->getIterator(); - } else { - throw new Exception('in() expects an iterable value'); - } - } - - foreach ($iterator as $item) { + foreach ($enums as $item) { if ($item === $this) { return true; } @@ -43,7 +31,7 @@ trait Comparable return false; } - public function notIn(array|object $enums): bool + public function notIn(iterable $enums): bool { return ! $this->in($enums); }