Completed
Push — master ( f3d96d...f3995b )
by Simonas
02:37
created

CompletionSuggest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 1
dl 62
loc 62
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 6 1
A getType() 4 4 1
A getName() 4 4 1
A toArray() 15 15 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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