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

CascadeExtraction::addExtraction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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
}