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

ContextSuggest   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 76
Duplicated Lines 22.37 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 1
cbo 1
dl 17
loc 76
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A getName() 0 4 1
A getType() 0 4 1
A toArray() 17 17 3

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
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