Passed
Pull Request — 2.1 (#71)
by Vincent
14:21 queued 08:17
created

NestedFilters   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
eloc 10
c 1
b 0
f 0
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 7 4
1
<?php
2
3
namespace Bdf\Prime\Query\Closure;
4
5
use Bdf\Prime\Query\Contract\Whereable;
6
use Doctrine\DBAL\Query\Expression\CompositeExpression;
7
8
/**
9
 * Adapt array of filters to a closure compatible with Whereable::where()
10
 *
11
 * @see Whereable::where()
12
 * @see Whereable::nested()
13
 *
14
 * @internal
15
 */
16
final class NestedFilters
17
{
18
    /**
19
     * @var list<array{string|NestedFilters, string|null, mixed|null}>
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\Query\Closure\list was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
20
     */
21
    private array $filters;
22
23
    /**
24
     * @var CompositeExpression::TYPE_AND|CompositeExpression::TYPE_OR
25
     */
26
    private string $type;
27
28
    /**
29
     * @param list<array{string|NestedFilters, string|null, mixed|null}> $filters
30
     * @param CompositeExpression::TYPE_AND|CompositeExpression::TYPE_OR $type
31
     */
32 10
    public function __construct(array $filters, string $type = CompositeExpression::TYPE_AND)
33
    {
34 10
        $this->filters = $filters;
0 ignored issues
show
Documentation Bug introduced by
It seems like $filters of type array is incompatible with the declared type Bdf\Prime\Query\Closure\list of property $filters.

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...
35 10
        $this->type = $type;
0 ignored issues
show
Documentation Bug introduced by
It seems like $type of type string is incompatible with the declared type Doctrine\DBAL\Query\Expression\CompositeExpression of property $type.

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...
36
    }
37
38 8
    public function __invoke(Whereable $query): void
39
    {
40 8
        foreach ($this->filters as [$column, $operator, $value]) {
41 8
            if ($this->type === CompositeExpression::TYPE_AND) {
42 8
                $query->where($column, $operator, $value);
43 1
            } elseif ($this->type === CompositeExpression::TYPE_OR) {
44 1
                $query->orWhere($column, $operator, $value);
45
            }
46
        }
47
    }
48
}
49