Completed
Pull Request — master (#76)
by
unknown
02:44
created

ContextSuggest::getName()   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 0
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\Suggest;
13
14
use ONGR\ElasticsearchDSL\BuilderInterface;
15
use ONGR\ElasticsearchDSL\ParametersTrait;
16
17
class ContextSuggest implements BuilderInterface
18
{
19
    use ParametersTrait;
20
21
    const DEFAULT_SIZE = 3;
22
23
    /**
24
     * @var string
25
     */
26
    private $name;
27
    /**
28
     * @var string
29
     */
30
    private $text;
31
    /**
32
     * @var array
33
     */
34
    private $context;
35
36
    /**
37
     * ContextSuggest constructor.
38
     * @param string $name
39
     * @param string $text
40
     * @param array $context
41
     * @param array $parameters
42
     */
43
    public function __construct($name, $text, $context, $parameters = [])
44
    {
45
        $this->name = $name;
46
        $this->text = $text;
47
        $this->context = $context;
48
        $this->setParameters($parameters);
49
        $this->addParameter('context', $context);
50
    }
51
52
    /**
53
     * Returns suggest name
54
     *
55
     * @return string
56
     */
57
    public function getName()
58
    {
59
        return $this->name;
60
    }
61
62
    /**
63
     * Returns element type.
64
     *
65
     * @return string
66
     */
67
    public function getType()
68
    {
69
        return 'context_suggest';
70
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75
    public function toArray()
76
    {
77
        if (!$this->hasParameter('field')) {
78
            $this->addParameter('field', '_all');
79
        }
80
81
        if (!$this->hasParameter('size')) {
82
            $this->addParameter('size', self::DEFAULT_SIZE);
83
        }
84
85
        $output = [
86
            $this->name => [
87
                'text' => $this->text,
88
                'completion' => $this->getParameters(),
89
            ]
90
        ];
91
92
        return $output;
93
    }
94
}
95