From 68c663ae6d66967f16cc1226ff6a5101b207a39b Mon Sep 17 00:00:00 2001 From: Priyadi Iman Nurcahyo <1102197+priyadi@users.noreply.github.com> Date: Thu, 15 Feb 2024 16:18:54 +0700 Subject: [PATCH] refactor: remove criteria from __construct --- CHANGELOG.md | 1 + src/LazyMatching/LazyMatchingCollection.php | 3 ++- src/LazyMatching/LazyMatchingReadableCollection.php | 4 ++-- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 167a0a5..e265b66 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 2.1.3 * Improve lazy-matching test. +* refactor: remove criteria from __construct ## 2.1.2 diff --git a/src/LazyMatching/LazyMatchingCollection.php b/src/LazyMatching/LazyMatchingCollection.php index 4365a23..4652a70 100644 --- a/src/LazyMatching/LazyMatchingCollection.php +++ b/src/LazyMatching/LazyMatchingCollection.php @@ -27,6 +27,7 @@ class LazyMatchingCollection extends SelectableCollectionDecorator { public function matching(Criteria $criteria): ReadableCollection&Selectable { - return new LazyMatchingReadableCollection($this->getWrapped(), $criteria); + return (new LazyMatchingReadableCollection($this->getWrapped())) + ->matching($criteria); } } diff --git a/src/LazyMatching/LazyMatchingReadableCollection.php b/src/LazyMatching/LazyMatchingReadableCollection.php index 4f90059..dd8c04e 100644 --- a/src/LazyMatching/LazyMatchingReadableCollection.php +++ b/src/LazyMatching/LazyMatchingReadableCollection.php @@ -31,13 +31,13 @@ class LazyMatchingReadableCollection extends SelectableReadableCollectionDecorat * @var null|(ReadableCollection&Selectable) */ private $resultCache = null; + private ?Criteria $criteria = null; /** * @param ReadableCollection $collection */ public function __construct( - ReadableCollection $collection, - private ?Criteria $criteria = null + ReadableCollection $collection ) { if (!$collection instanceof Selectable) { throw new \InvalidArgumentException('Collection must be selectable');