Passed
Push — feature-FRAM-112-closure-filte... ( c8f14f )
by Vincent
06:52
created

AndFilter   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Test Coverage

Coverage 64.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
eloc 12
c 1
b 0
f 0
dl 0
loc 67
ccs 11
cts 17
cp 0.6471
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A count() 0 3 1
A offsetGet() 0 3 1
A __construct() 0 7 3
A offsetSet() 0 3 1
A getIterator() 0 3 1
A offsetExists() 0 3 1
A offsetUnset() 0 3 1
1
<?php
2
3
namespace Bdf\Prime\Query\Closure\Filter;
4
5
use ArrayAccess;
6
use BadMethodCallException;
7
use Countable;
8
use Generator;
9
10
use IteratorAggregate;
11
12
use function array_push;
13
14
/**
15
 * @implements IteratorAggregate<int, AtomicFilter|OrFilter>
16
 */
17
final class AndFilter implements IteratorAggregate, Countable, ArrayAccess
18
{
19
    /**
20
     * @var list<AtomicFilter|OrFilter>
0 ignored issues
show
Bug introduced by
The type Bdf\Prime\Query\Closure\Filter\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...
21
     */
22
    public array $filters = [];
23
24
    /**
25
     * @param AtomicFilter|OrFilter|AndFilter ...$filters
26
     */
27 12
    public function __construct(...$filters)
28
    {
29 12
        foreach ($filters as $filter) {
30 12
            if ($filter instanceof AndFilter) {
31 6
                array_push($this->filters, ...$filter->filters);
32
            } else {
33 12
                $this->filters[] = $filter;
34
            }
35
        }
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 10
    public function getIterator(): Generator
42
    {
43 10
        yield from $this->filters;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function offsetExists($offset): bool
50
    {
51
        return isset($this->filters[$offset]);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 3
    public function offsetGet($offset)
58
    {
59 3
        return $this->filters[$offset];
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function offsetSet($offset, $value): void
66
    {
67
        throw new BadMethodCallException('Filters are immutable');
68
    }
69
70
    /**
71
     * {@inheritdoc}
72
     */
73
    public function offsetUnset($offset): void
74
    {
75
        throw new BadMethodCallException('Filters are immutable');
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81 3
    public function count(): int
82
    {
83 3
        return count($this->filters);
84
    }
85
}
86