@@ -485,28 +485,40 @@ public function find($key, $value): ?DataObject
485485
486486 public function filter (...$ args ): static
487487 {
488- $ filters = $ this ->normaliseFilterArgs ($ args , __FUNCTION__ );
489488 $ list = clone $ this ;
490- $ list ->rows = $ this ->getMatches ($ filters );
489+
490+ if ($ list ->rows ) {
491+ $ filters = $ list ->normaliseFilterArgs ($ args , __FUNCTION__ );
492+ $ list ->rows = $ this ->getMatches ($ filters );
493+ }
494+
491495 return $ list ;
492496 }
493497
494498 public function filterAny (...$ args ): static
495499 {
496- $ filters = $ this ->normaliseFilterArgs ($ args , __FUNCTION__ );
497500 $ list = clone $ this ;
498- $ list ->rows = $ this ->getMatches ($ filters , true );
501+
502+ if ($ list ->rows ) {
503+ $ filters = $ list ->normaliseFilterArgs ($ args , __FUNCTION__ );
504+ $ list ->rows = $ this ->getMatches ($ filters , true );
505+ }
506+
499507 return $ list ;
500508 }
501509
502510 public function exclude (...$ args ): static
503511 {
504- $ filters = $ this ->normaliseFilterArgs ($ args , __FUNCTION__ );
505- $ toRemove = $ this ->getMatches ($ filters );
506512 $ list = clone $ this ;
507- foreach ($ toRemove as $ id => $ row ) {
508- unset($ list ->rows [$ id ]);
513+
514+ if ($ list ->rows ) {
515+ $ filters = $ list ->normaliseFilterArgs ($ args , __FUNCTION__ );
516+ $ toRemove = $ list ->getMatches ($ filters );
517+ foreach ($ toRemove as $ id => $ row ) {
518+ unset($ list ->rows [$ id ]);
519+ }
509520 }
521+
510522 return $ list ;
511523 }
512524
@@ -517,12 +529,16 @@ public function exclude(...$args): static
517529 */
518530 public function excludeAny (...$ args ): static
519531 {
520- $ filters = $ this ->normaliseFilterArgs ($ args , __FUNCTION__ );
521- $ toRemove = $ this ->getMatches ($ filters , true );
522532 $ list = clone $ this ;
523- foreach ($ toRemove as $ id => $ row ) {
524- unset($ list ->rows [$ id ]);
533+
534+ if ($ list ->rows ) {
535+ $ filters = $ list ->normaliseFilterArgs ($ args , __FUNCTION__ );
536+ $ toRemove = $ list ->getMatches ($ filters , true );
537+ foreach ($ toRemove as $ id => $ row ) {
538+ unset($ list ->rows [$ id ]);
539+ }
525540 }
541+
526542 return $ list ;
527543 }
528544
0 commit comments