1010use Yiisoft \Arrays \ArrayHelper ;
1111use Yiisoft \Data \Reader \DataReaderException ;
1212use Yiisoft \Data \Reader \DataReaderInterface ;
13+ use Yiisoft \Data \Reader \Filter \All ;
1314use Yiisoft \Data \Reader \FilterHandlerInterface ;
1415use Yiisoft \Data \Reader \FilterInterface ;
1516use Yiisoft \Data \Reader \Iterable \FilterHandler \AllHandler ;
5354final class IterableDataReader implements DataReaderInterface
5455{
5556 private ?Sort $ sort = null ;
56- private ? FilterInterface $ filter = null ;
57+ private FilterInterface $ filter ;
5758
5859 /**
5960 * @psalm-var non-negative-int|null
@@ -93,6 +94,7 @@ public function __construct(
9394 new NotHandler (),
9495 ]);
9596 $ this ->context = new Context ($ this ->coreFilterHandlers , $ this ->valueReader );
97+ $ this ->filter = new All ();
9698 }
9799
98100 /**
@@ -111,10 +113,7 @@ public function withAddedFilterHandlers(FilterHandlerInterface ...$filterHandler
111113 return $ new ;
112114 }
113115
114- /**
115- * @psalm-return $this
116- */
117- public function withFilter (?FilterInterface $ filter ): static
116+ public function withFilter (FilterInterface $ filter ): static
118117 {
119118 $ new = clone $ this ;
120119 $ new ->filter = $ filter ;
@@ -216,8 +215,8 @@ private function internalRead(bool $useLimitAndOffset): array
216215 continue ;
217216 }
218217
219- // Filter items.
220- if ($ this ->filter === null || $ this -> matchFilter ($ item , $ this ->filter )) {
218+ // Filter items
219+ if ($ this ->matchFilter ($ item , $ this ->filter )) {
221220 $ data [$ key ] = $ item ;
222221 }
223222 }
@@ -320,7 +319,7 @@ private function iterableToArray(iterable $iterable): array
320319 return $ iterable instanceof Traversable ? iterator_to_array ($ iterable ) : $ iterable ;
321320 }
322321
323- public function getFilter (): ? FilterInterface
322+ public function getFilter (): FilterInterface
324323 {
325324 return $ this ->filter ;
326325 }
0 commit comments