Completed
Push — master ( df9952...f86661 )
by Hannes
04:17 queued 02:11
created

ExpressionFilter::filter()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 4
nc 3
nop 1
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 ExpressionFilter Search expression
16
     */
17
    private $expression;
18
19
    /**
20
     * Set search expression
21
     */
22
    public function __construct(ExpressionInterface $expression)
23
    {
24
        $this->expression = $expression;
0 ignored issues
show
Documentation Bug introduced by
It seems like $expression of type object<hanneskod\yaysond...on\ExpressionInterface> is incompatible with the declared type object<hanneskod\yaysond...ilter\ExpressionFilter> of property $expression.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
25
    }
26
27
    public function filter(\Traversable $documents): \Generator
28
    {
29
        foreach ($documents as $id => $doc) {
30
            if ($this->expression->evaluate($doc)) {
0 ignored issues
show
Bug introduced by
The method evaluate() does not seem to exist on object<hanneskod\yaysond...ilter\ExpressionFilter>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
31
                yield $id => $doc;
32
            }
33
        }
34
    }
35
}
36