Passed
Pull Request — master (#38)
by Teye
06:17
created

ExpressionFilter   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 6
c 0
b 0
f 0
dl 0
loc 22
ccs 5
cts 5
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A toArray() 0 5 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Filters;
5
6
/**
7
 * Class ExpressionFilter
8
 *
9
 * The expression filter allows for the implementation of arbitrary conditions, leveraging the Druid expression system.
10
 *
11
 * @package Level23\Druid\Filters
12
 */
13
class ExpressionFilter implements FilterInterface
14
{
15
    protected string $expression;
16
17
    /**
18
     * @param string $expression
19
     */
20 2
    public function __construct(string $expression)
21
    {
22 2
        $this->expression = $expression;
23
    }
24
25
    /**
26
     * Return the filter as it can be used in the druid query.
27
     *
28
     * @return array<string,string>
29
     */
30 2
    public function toArray(): array
31
    {
32
        return [
33 2
            'type'       => 'expression',
34 2
            'expression' => $this->expression,
35
        ];
36
    }
37
}