SpatialRectangularFilter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
cc 1
nc 1
nop 3
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Filters;
5
6
/**
7
 * Class SpatialRectangularFilter
8
 *
9
 * @package Level23\Druid\Filters
10
 */
11
class SpatialRectangularFilter implements FilterInterface
12
{
13
    protected string $dimension;
14
15
    /**
16
     * @var float[]
17
     */
18
    protected array $minCoords;
19
20
    /**
21
     * @var float[]
22
     */
23
    protected array $maxCoords;
24
25
    /**
26
     * SpatialRectangularFilter constructor.
27
     *
28
     * @param string  $dimension The dimension to filter on
29
     * @param float[] $minCoords List of minimum dimension coordinates for coordinates [x, y, z, …]
30
     * @param float[] $maxCoords List of maximum dimension coordinates for coordinates [x, y, z, …]
31
     */
32 1
    public function __construct(
33
        string $dimension,
34
        array $minCoords,
35
        array $maxCoords
36
    ) {
37 1
        $this->dimension = $dimension;
38 1
        $this->minCoords = $minCoords;
39 1
        $this->maxCoords = $maxCoords;
40
    }
41
42
    /**
43
     * Return the filter as it can be used in the druid query.
44
     *
45
     * @return array<string,string|array<string,string|float[]>>
46
     */
47 1
    public function toArray(): array
48
    {
49 1
        return [
50 1
            'type'      => 'spatial',
51 1
            'dimension' => $this->dimension,
52 1
            'bound'     => [
53 1
                'type'      => 'rectangular',
54 1
                'minCoords' => $this->minCoords,
55 1
                'maxCoords' => $this->maxCoords,
56 1
            ],
57 1
        ];
58
    }
59
}