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

ContextSuggest::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 6
nc 1
nop 4
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 View Code Duplication
    public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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 = [$this->name => [
86
            'text' => $this->text,
87
            'completion' => $this->getParameters(),
88
        ]];
89
90
        return $output;
91
    }
92
}
93