AndHavingFilter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 48
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getHavingFilters() 0 3 1
A addHavingFilter() 0 3 1
A toArray() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\HavingFilters;
5
6
class AndHavingFilter implements HavingFilterInterface, LogicalExpressionHavingFilterInterface
7
{
8
    /**
9
     * @var \Level23\Druid\HavingFilters\HavingFilterInterface[]
10
     */
11
    protected array $filters;
12
13
    /**
14
     * AndHavingFilter constructor.
15
     *
16
     * @param \Level23\Druid\HavingFilters\HavingFilterInterface[] $filters
17
     */
18 18
    public function __construct(array $filters)
19
    {
20 18
        $this->filters = $filters;
21
    }
22
23
    /**
24
     * Return the having filter as it can be used in a druid query.
25
     *
26
     * @return array<string,string|array<array<string,string|float|array<mixed>|bool>>>
27
     */
28 3
    public function toArray(): array
29
    {
30 3
        return [
31 3
            'type'        => 'and',
32 3
            'havingSpecs' => array_map(fn(HavingFilterInterface $filter) => $filter->toArray(), $this->filters),
33 3
        ];
34
    }
35
36
    /**
37
     * Add an extra filter to our logical expression filter.
38
     *
39
     * @param \Level23\Druid\HavingFilters\HavingFilterInterface $having
40
     */
41 3
    public function addHavingFilter(HavingFilterInterface $having): void
42
    {
43 3
        $this->filters[] = $having;
44
    }
45
46
    /**
47
     * Return all having filters which are used by this logical expression filter.
48
     *
49
     * @return \Level23\Druid\HavingFilters\HavingFilterInterface[]
50
     */
51 2
    public function getHavingFilters(): array
52
    {
53 2
        return $this->filters;
54
    }
55
}