VirtualColumn   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 12
dl 0
loc 36
ccs 10
cts 10
cp 1
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toArray() 0 7 1
A __construct() 0 5 2
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\VirtualColumns;
5
6
use Level23\Druid\Types\DataType;
7
8
class VirtualColumn implements VirtualColumnInterface
9
{
10
    protected string $name;
11
12
    protected string $expression;
13
14
    protected DataType $outputType;
15
16
    /**
17
     * VirtualColumn constructor.
18
     *
19
     * @param string $expression An druid expression
20
     * @param string $as
21
     * @param string|DataType $outputType
22
     *
23
     * @see https://druid.apache.org/docs/latest/misc/math-expr.html
24
     */
25 23
    public function __construct(string $expression, string $as, string|DataType $outputType = DataType::FLOAT)
26
    {
27 23
        $this->name       = $as;
28 23
        $this->expression = $expression;
29 23
        $this->outputType = is_string($outputType) ? DataType::from(strtolower($outputType)) : $outputType;
30
    }
31
32
    /**
33
     * Return the virtual column as it can be used in a druid query.
34
     *
35
     * @return array<string,string>
36
     */
37 8
    public function toArray(): array
38
    {
39 8
        return [
40 8
            'type'       => 'expression',
41 8
            'name'       => $this->name,
42 8
            'expression' => $this->expression,
43 8
            'outputType' => $this->outputType->value,
44 8
        ];
45
    }
46
}
47