These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | /** |
||
18 | * @deprecated CompletionSuggest is deprecated, use Suggest instead |
||
19 | */ |
||
20 | View Code Duplication | class CompletionSuggest implements BuilderInterface |
|
0 ignored issues
–
show
|
|||
21 | { |
||
22 | use ParametersTrait; |
||
23 | |||
24 | const DEFAULT_SIZE = 3; |
||
25 | |||
26 | /** |
||
27 | * @var string |
||
28 | */ |
||
29 | private $name; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | private $text; |
||
35 | |||
36 | public function __construct($name, $text, $parameters = []) |
||
37 | { |
||
38 | $this->name = $name; |
||
39 | $this->text = $text; |
||
40 | $this->setParameters($parameters); |
||
41 | } |
||
42 | |||
43 | /** |
||
44 | * Returns element type. |
||
45 | * |
||
46 | * @return string |
||
47 | */ |
||
48 | public function getType() |
||
49 | { |
||
50 | return 'completion_suggest'; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * Returns suggest name |
||
55 | * |
||
56 | * @return string |
||
57 | */ |
||
58 | public function getName() |
||
59 | { |
||
60 | return $this->name; |
||
61 | } |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function toArray() |
||
67 | { |
||
68 | if (!$this->hasParameter('field')) { |
||
69 | $this->addParameter('field', 'suggest'); |
||
70 | } |
||
71 | |||
72 | if (!$this->hasParameter('size')) { |
||
73 | $this->addParameter('size', self::DEFAULT_SIZE); |
||
74 | } |
||
75 | |||
76 | $output = [$this->name => [ |
||
77 | 'text' => $this->text, |
||
78 | 'completion' => $this->getParameters() |
||
79 | ]]; |
||
80 | |||
81 | return $output; |
||
82 | } |
||
83 | } |
||
84 |
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.