Code Duplication    Length = 64-64 lines in 2 locations

src/Suggest/CompletionSuggest.php 1 location

@@ 20-83 (lines=64) @@
17
/**
18
 * @deprecated CompletionSuggest is deprecated, use Suggest instead
19
 */
20
class CompletionSuggest implements BuilderInterface
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

src/Suggest/TermSuggest.php 1 location

@@ 20-83 (lines=64) @@
17
/**
18
 * @deprecated TermSuggestClass is deprecated, use Suggest instead
19
 */
20
class TermSuggest implements BuilderInterface
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 'term_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', '_all');
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
            'term' => $this->getParameters(),
79
        ]];
80
81
        return $output;
82
    }
83
}
84