Completed
Push — master ( 6c9334...f3ba17 )
by Simonas
02:26
created

ScriptQuery::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
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\Query\Specialized;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
/**
18
 * Represents Elasticsearch "script" query.
19
 *
20
 * @link https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-script-query.html
21
 */
22
class ScriptQuery implements BuilderInterface
23
{
24
    use ParametersTrait;
25
26
    /**
27
     * @var string
28
     */
29
    private $script;
30
31
    /**
32
     * @param string $script     Script
33
     * @param array  $parameters Optional parameters
34
     */
35
    public function __construct($script, array $parameters = [])
36
    {
37
        $this->script = $script;
38
        $this->setParameters($parameters);
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function getType()
45
    {
46
        return 'script';
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function toArray()
53
    {
54
        $query = ['inline' => $this->script];
55
        $output = $this->processArray($query);
56
57
        return [$this->getType() => ['script' => $output]];
58
    }
59
}
60