ExpressionFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A filter() 0 8 3
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace hanneskod\yaysondb\Filter;
6
7
use hanneskod\yaysondb\Expression\ExpressionInterface;
8
9
/**
10
 * Filter documents matching search expression
11
 */
12
class ExpressionFilter implements FilterInterface
13
{
14
    /**
15
     * @var ExpressionInterface Search expression
16
     */
17
    private $expression;
18
19
    /**
20
     * Set search expression
21
     */
22
    public function __construct(ExpressionInterface $expression)
23
    {
24
        $this->expression = $expression;
25
    }
26
27
    public function filter(\Traversable $documents): \Generator
28
    {
29
        foreach ($documents as $id => $doc) {
30
            if ($this->expression->evaluate($doc)) {
31
                yield $id => $doc;
32
            }
33
        }
34
    }
35
}
36