Completed
Pull Request — master (#66)
by
unknown
02:32
created

Suggest::toArray()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 17
rs 9.4285
cc 3
eloc 9
nc 4
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
16
class Suggest implements BuilderInterface
17
{
18
    const DEFAULT_SIZE = 3;
19
20
    /**
21
     * @var string
22
     */
23
    private $name;
24
25
    /**
26
     * @var string
27
     */
28
    private $text;
29
30
    /**
31
     * @var array
32
     */
33
    private $params;
34
35
    public function __construct($name, $text, $params = [])
36
    {
37
        $this->name = $name;
38
        $this->text = $text;
39
        $this->params = $params;
40
    }
41
42
    /**
43
     * Returns element type.
44
     *
45
     * @return string
46
     */
47
    public function getType()
48
    {
49
        return 'suggest';
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
     * {@inheritdoc}
64
     */
65
    public function toArray()
66
    {
67
        if (!isset($this->params['field'])) {
68
            $this->params['field'] = '_all';
69
        }
70
71
        if (!isset($this->params['size'])) {
72
            $this->params['size'] = self::DEFAULT_SIZE;
73
        }
74
75
        $output = [
76
            'text' => $this->text,
77
            'term' => $this->params,
78
        ];
79
80
        return $output;
81
    }
82
}