Passed
Pull Request — master (#38)
by Teye
05:43
created

SpatialRadiusFilter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 14
c 0
b 0
f 0
dl 0
loc 42
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 9 1
A __construct() 0 8 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Filters;
5
6
/**
7
 * Class SpatialRadiusFilter
8
 *
9
 * @package Level23\Druid\Filters
10
 */
11
class SpatialRadiusFilter implements FilterInterface
12
{
13
    protected string $dimension;
14
15
    /**
16
     * @var float[]
17
     */
18
    protected array $coords;
19
20
    protected float $radius;
21
22
    /**
23
     * SpatialRadiusFilter constructor.
24
     *
25
     * @param string  $dimension The dimension to filter on
26
     * @param float[] $coords    Origin coordinates in the form [x, y, z, …]
27
     * @param float   $radius    The float radius value
28
     */
29 1
    public function __construct(
30
        string $dimension,
31
        array $coords,
32
        float $radius
33
    ) {
34 1
        $this->dimension = $dimension;
35 1
        $this->coords    = $coords;
36 1
        $this->radius    = $radius;
37
    }
38
39
    /**
40
     * Return the filter as it can be used in the druid query.
41
     *
42
     * @return array<string,string|array<string,string|float|float[]>>
43
     */
44 1
    public function toArray(): array
45
    {
46
        return [
47 1
            'type'      => 'spatial',
48 1
            'dimension' => $this->dimension,
49
            'bound'     => [
50 1
                'type'   => 'radius',
51 1
                'coords' => $this->coords,
52 1
                'radius' => $this->radius,
53
            ],
54
        ];
55
    }
56
}