Habari\Comments::filter PHP Method

filter() public method

Filter Comments using a callback function
public filter ( Callable | array $filter ) : Comments
$filter Callable | array A callback function that returns true if the item passed in should be kept
return Comments The filtered comments
    public function filter($filter)
    {
        if (is_callable($filter)) {
            $output = array();
            foreach ($this as $comment) {
                if ($filter($comment)) {
                    $output[] = $comment;
                }
            }
            return new Comments($output);
        } elseif (is_array($filter)) {
            $filters = $filter;
            $filter = function ($item) use($filters) {
                $output = false;
                foreach ($filters as $filter) {
                    $output = $output || $item->{$filter};
                }
                return $output;
            };
            return $this->filter($filter);
        } else {
            return $this;
        }
    }