Spellcheck   A
last analyzed

Complexity

Total Complexity 21

Size/Duplication

Total Lines 241
Duplicated Lines 1.24 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 21
lcom 1
cbo 1
dl 3
loc 241
ccs 0
cts 78
cp 0
rs 10
c 0
b 0
f 0

19 Methods

Rating   Name   Duplication   Size   Complexity  
A preMergeParams() 3 6 3
A init() 0 4 1
A setQuery() 0 4 1
A spellcheck() 0 4 1
A build() 0 4 1
A reload() 0 4 1
A setDictionary() 0 4 1
A setCount() 0 4 1
A setAlternativeTermCount() 0 4 1
A onlyMorePopular() 0 4 1
A setMaxResultsForSuggest() 0 4 1
A collate() 0 4 1
A setMaxCollations() 0 4 1
A setMaxCollationTries() 0 4 1
A setCollateParam() 0 4 1
A collateExtendedResults() 0 4 1
A setCollateMaxCollectDocs() 0 4 1
A setAccuracy() 0 4 1
A setDictionaryParam() 0 4 1

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
namespace PSolr\Request;
4
5
/**
6
 * @see http://wiki.apache.org/solr/SpellCheckComponent
7
 *
8
 * @method \PSolr\Response\Spellcheck sendRequest(\PSolr\Request\SolrClient $solr, $headers = null, array $options = array())
9
 */
10
class Spellcheck extends SolrRequest implements ComponentInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $handlerName = 'spell';
16
17
    /**
18
     * $var string
19
     */
20
    protected $responseClass = '\PSolr\Response\Spellcheck';
21
22
    /**
23
     * {@inheritDoc}
24
     *
25
     * Sets the query that is used in the base query.
26
     */
27
    public function preMergeParams(SolrRequest $request)
28
    {
29 View Code Duplication
        if (isset($request['q']) && !isset($this['hl.q'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
30
            $this['spellcheck.q'] = $request['q'];
31
        }
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     *
37
     * Enables spell checking.
38
     */
39
    public function init()
40
    {
41
        $this->spellcheck();
42
    }
43
44
    /**
45
     * @param string $query
46
     *
47
     * @return \PSolr\Request\Suggest
48
     *
49
     * @see http://wiki.apache.org/solr/SpellCheckComponent#q_OR_spellcheck.q
50
     */
51
    public function setQuery($query)
52
    {
53
        return $this->set('spellcheck.q', $query);
54
    }
55
56
    /**
57
     * @param bool $spellcheck
58
     *
59
     * @return \Psolr\Component\Spellcheck
60
     *
61
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck
62
     */
63
    public function spellcheck($spellcheck = true)
0 ignored issues
show
Coding Style Best Practice introduced by
Please use __construct() instead of a PHP4-style constructor that is named after the class.
Loading history...
64
    {
65
        return $this->set('spellcheck', $spellcheck);
66
    }
67
68
    /**
69
     * @param bool $build
70
     *
71
     * @return \Psolr\Component\Spellcheck
72
     *
73
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.build
74
     */
75
    public function build($build = true)
76
    {
77
        return $this->set('spellcheck.build', $build);
78
    }
79
80
    /**
81
     * @param bool $reload
82
     *
83
     * @return \Psolr\Component\Spellcheck
84
     *
85
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.reload
86
     */
87
    public function reload($reload = true)
88
    {
89
        return $this->set('spellcheck.reload', $reload);
90
    }
91
92
    /**
93
     * @param string $dictionary
94
     *
95
     * @return \Psolr\Component\Spellcheck
96
     *
97
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.dictionary
98
     */
99
    public function setDictionary($dictionary)
100
    {
101
        return $this->set('spellcheck.dictionary', $dictionary);
102
    }
103
104
    /**
105
     * @param int $count
106
     *
107
     * @return \Psolr\Component\Spellcheck
108
     *
109
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.count
110
     */
111
    public function setCount($count)
112
    {
113
        return $this->set('spellcheck.dictionary', $count);
114
    }
115
116
    /**
117
     * @param int $count
118
     *
119
     * @return \Psolr\Component\Spellcheck
120
     *
121
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.alternativeTermCount
122
     */
123
    public function setAlternativeTermCount($count)
124
    {
125
        return $this->set('spellcheck.alternativeTermCount', $count);
126
    }
127
128
    /**
129
     * @param bool $onlyMorePopular
130
     *
131
     * @return \Psolr\Component\Spellcheck
132
     *
133
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.onlyMorePopular
134
     */
135
    public function onlyMorePopular($onlyMorePopular = true)
136
    {
137
        return $this->set('spellcheck.onlyMorePopular', $onlyMorePopular);
138
    }
139
140
    /**
141
     * @param int $maxResults
142
     *
143
     * @return \Psolr\Component\Spellcheck
144
     *
145
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxResultsForSuggest
146
     */
147
    public function setMaxResultsForSuggest($maxResults)
148
    {
149
        return $this->set('spellcheck.maxResultsForSuggest', $maxResults);
150
    }
151
152
    /**
153
     * @param bool $collate
154
     *
155
     * @return \Psolr\Component\Spellcheck
156
     *
157
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collate
158
     */
159
    public function collate($collate = true)
160
    {
161
        return $this->set('spellcheck.collate', $collate);
162
    }
163
164
    /**
165
     * @param int $maxCollations
166
     *
167
     * @return \Psolr\Component\Spellcheck
168
     *
169
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxCollations
170
     */
171
    public function setMaxCollations($maxCollations)
172
    {
173
        return $this->set('spellcheck.maxCollations', $maxCollations);
174
    }
175
176
    /**
177
     * @param int $maxTries
178
     *
179
     * @return \Psolr\Component\Spellcheck
180
     *
181
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.maxCollationTries
182
     */
183
    public function setMaxCollationTries($maxTries)
184
    {
185
        return $this->set('spellcheck.maxCollationTries', $maxTries);
186
    }
187
188
    /**
189
     * @param string $param
190
     * @param string $value
191
     *
192
     * @return \Psolr\Component\Spellcheck
193
     *
194
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateParam.XX
195
     */
196
    public function setCollateParam($param, $value)
197
    {
198
        return $this->set('spellcheck.collateParam.' . $param, $value);
199
    }
200
201
    /**
202
     * @param bool $collate
203
     *
204
     * @return \Psolr\Component\Spellcheck
205
     *
206
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateExtendedResults
207
     */
208
    public function collateExtendedResults($collate = true)
209
    {
210
        return $this->set('spellcheck.collateExtendedResults', $collate);
211
    }
212
213
    /**
214
     * @param int $maxDocs
215
     *
216
     * @return \Psolr\Component\Spellcheck
217
     *
218
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.collateMaxCollectDocs
219
     */
220
    public function setCollateMaxCollectDocs($maxDocs)
221
    {
222
        return $this->set('spellcheck.collateMaxCollectDocs', $maxDocs);
223
    }
224
225
    /**
226
     * @param float $accuracy
227
     *
228
     * @return \Psolr\Component\Spellcheck
229
     *
230
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck.accuracy
231
     */
232
    public function setAccuracy($accuracy)
233
    {
234
        return $this->set('spellcheck.accuracy', $accuracy);
235
    }
236
237
    /**
238
     * @param string $dictionary
239
     * @param string $key
240
     * @param string $value
241
     *
242
     * @return \Psolr\Component\Spellcheck
243
     *
244
     * @see http://wiki.apache.org/solr/SpellCheckComponent#spellcheck..3CDICT_NAME.3E.key
245
     */
246
    public function setDictionaryParam($dictionary, $key, $value)
247
    {
248
        return $this->set('spellcheck.' . $dictionary . '.' . $key, $value);
249
    }
250
}
251