Passed
Pull Request — master (#22)
by Teye
05:37
created

CascadeExtraction   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addExtraction() 0 3 1
A toArray() 0 7 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Level23\Druid\Extractions;
5
6
class CascadeExtraction implements ExtractionInterface
7
{
8
    /**
9
     * @var array|\Level23\Druid\Extractions\ExtractionInterface[]
10
     */
11
    protected $extractions = [];
12
13
    /**
14
     * CascadeExtraction constructor.
15
     *
16
     * @param \Level23\Druid\Extractions\ExtractionInterface ...$extractions
17
     */
18 2
    public function __construct(...$extractions)
19
    {
20 2
        $this->extractions = $extractions;
21 2
    }
22
23
    /**
24
     * Add an extraction function to our list of functions to apply.
25
     *
26
     * @param \Level23\Druid\Extractions\ExtractionInterface $extraction
27
     */
28 2
    public function addExtraction(ExtractionInterface $extraction)
29
    {
30 2
        $this->extractions[] = $extraction;
31 2
    }
32
33
    /**
34
     * Return the Extraction Function so it can be used in a druid query.
35
     *
36
     * @return array
37
     */
38 2
    public function toArray(): array
39
    {
40
        return [
41 2
            'type'          => 'cascade',
42 2
            'extractionFns' => array_map(function (ExtractionInterface $extraction) {
43 2
                return $extraction->toArray();
44 2
            }, $this->extractions),
45
        ];
46
    }
47
}