Skip to content

Commit

Permalink
Implement filter method on check collection.
Browse files Browse the repository at this point in the history
  • Loading branch information
felixarntz committed Nov 2, 2023
1 parent 6353199 commit 6b9df7f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
18 changes: 18 additions & 0 deletions includes/Checker/Default_Check_Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
11 changes: 4 additions & 7 deletions includes/Checker/Default_Check_Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
);
}
}

0 comments on commit 6b9df7f

Please sign in to comment.