JavascriptFilter::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Filters;
5
6
/**
7
 * Class JavascriptFilter
8
 *
9
 * The JavaScript filter matches a dimension against the specified JavaScript function predicate.
10
 * The filter matches values for which the function returns true.
11
 *
12
 * The function takes a single argument, the dimension value, and returns either true or false.
13
 *
14
 * @package Level23\Druid\Filters
15
 */
16
class JavascriptFilter implements FilterInterface
17
{
18
    protected string $dimension;
19
20
    protected string $javascriptFunction;
21
22
    /**
23
     * JavascriptFilter constructor.
24
     *
25
     * @param string                   $dimension
26
     * @param string                   $javascriptFunction
27
     */
28 1
    public function __construct(
29
        string $dimension,
30
        string $javascriptFunction
31
    ) {
32 1
        $this->dimension          = $dimension;
33 1
        $this->javascriptFunction = $javascriptFunction;
34
    }
35
36
    /**
37
     * Return the filter as it can be used in the druid query.
38
     *
39
     * @return array<string,string|array<string,string|int|bool|array<mixed>>>
40
     */
41 1
    public function toArray(): array
42
    {
43 1
        return [
44 1
            'type'      => 'javascript',
45 1
            'dimension' => $this->dimension,
46 1
            'function'  => $this->javascriptFunction,
47 1
        ];
48
    }
49
}