diff --git a/includes/Checker/Default_Check_Collection.php b/includes/Checker/Default_Check_Collection.php index 8ff2ebef9..1c29fddd7 100644 --- a/includes/Checker/Default_Check_Collection.php +++ b/includes/Checker/Default_Check_Collection.php @@ -67,6 +67,24 @@ public function to_map(): array { return $this->checks; } + /** + * Returns a new check collection containing the subset of checks based on the given check filter function. + * + * @since n.e.x.t + * + * @param callable $filter_fn Filter function that accepts a single check object and should return a boolean for + * whether to include the check in the new collection. + * @return Check_Collection New check collection, effectively a subset of this one. + */ + public function filter( callable $filter_fn ): Check_Collection { + return new self( + array_filter( + $this->checks, + $filter_fn + ) + ); + } + /** * Returns a new check collection containing the subset of checks based on the given check slugs. * diff --git a/includes/Checker/Default_Check_Repository.php b/includes/Checker/Default_Check_Repository.php index 761d6f1d6..aa1670c14 100644 --- a/includes/Checker/Default_Check_Repository.php +++ b/includes/Checker/Default_Check_Repository.php @@ -102,13 +102,10 @@ public function get_checks( $flags = self::TYPE_ALL ) { } // Remove experimental checks before returning. - return new Default_Check_Collection( - array_filter( - $checks, - static function ( $check ) { - return $check->get_stability() !== Check::STABILITY_EXPERIMENTAL; - } - ) + return ( new Default_Check_Collection( $checks ) )->filter( + static function ( $check ) { + return $check->get_stability() !== Check::STABILITY_EXPERIMENTAL; + } ); } }