Completed
Push — master ( 72c6f5...0ae1e6 )
by Simonas
04:03
created

BucketScriptAggregation::setScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/*
4
 * This file is part of the ONGR package.
5
 *
6
 * (c) NFQ Technologies UAB <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace ONGR\ElasticsearchDSL\Aggregation\Pipeline;
13
14
/**
15
 * Class representing Bucket Script Pipeline Aggregation.
16
 *
17
 * @link https://goo.gl/miVxcx
18
 */
19
class BucketScriptAggregation extends AbstractPipelineAggregation
20
{
21
    /**
22
     * @var string
23
     */
24
    private $script;
25
26
    /**
27
     * @param string $name
28
     * @param array  $bucketsPath
29
     * @param string $script
30
     */
31
    public function __construct($name, $bucketsPath, $script = null)
32
    {
33
        parent::__construct($name, $bucketsPath);
34
        $this->setScript($script);
35
    }
36
37
    /**
38
     * @return string
39
     */
40
    public function getScript()
41
    {
42
        return $this->script;
43
    }
44
45
    /**
46
     * @param string $script
47
     */
48
    public function setScript($script)
49
    {
50
        $this->script = $script;
51
    }
52
53
    /**
54
     * {@inheritdoc}
55
     */
56
    public function getType()
57
    {
58
        return 'bucket_script';
59
    }
60
61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function getArray()
65
    {
66
        if (!$this->getScript()) {
67
            throw new \LogicException(
68
                sprintf(
69
                    '`%s` aggregation must have script set.',
70
                    $this->getName()
71
                )
72
            );
73
        }
74
75
        $out = [
76
            'buckets_path' => $this->getBucketsPath(),
77
            'script' => $this->getScript(),
78
        ];
79
80
        return $out;
81
    }
82
}
83