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 |
||
35 | class PMF_Instance_Elasticsearch |
||
36 | { |
||
37 | /** @var PMF_Configuration */ |
||
38 | protected $config; |
||
39 | |||
40 | /** @var Client */ |
||
41 | protected $client; |
||
42 | |||
43 | /** |
||
44 | * Elasticsearch mapping |
||
45 | * |
||
46 | * @var array |
||
47 | */ |
||
48 | private $mappings = [ |
||
49 | 'faqs' => [ |
||
50 | '_source' => [ |
||
51 | 'enabled' => true |
||
52 | ], |
||
53 | 'properties' => [ |
||
54 | 'id' => [ |
||
55 | 'type' => 'integer' |
||
56 | ], |
||
57 | 'question' => [ |
||
58 | 'type' => 'string', |
||
59 | 'analyzer' => 'autocomplete', |
||
60 | 'search_analyzer' => 'standard' |
||
61 | ], |
||
62 | 'answer' => [ |
||
63 | 'type' => 'string', |
||
64 | 'analyzer' => 'autocomplete', |
||
65 | 'search_analyzer' => 'standard' |
||
66 | ], |
||
67 | 'keywords' => [ |
||
68 | 'type' => 'string', |
||
69 | 'analyzer' => 'autocomplete', |
||
70 | 'search_analyzer' => 'standard' |
||
71 | ], |
||
72 | 'categories' => [ |
||
73 | 'type' => 'string', |
||
74 | 'analyzer' => 'autocomplete', |
||
75 | 'search_analyzer' => 'standard' |
||
76 | ] |
||
77 | ] |
||
78 | ] |
||
79 | ]; |
||
80 | /** |
||
81 | * Constructor. |
||
82 | * |
||
83 | * @param PMF_Configuration $config |
||
84 | */ |
||
85 | public function __construct(PMF_Configuration $config) |
||
90 | |||
91 | /** |
||
92 | * Creates the Elasticsearch index. |
||
93 | * |
||
94 | * @return array |
||
95 | */ |
||
96 | public function createIndex() |
||
101 | |||
102 | /** |
||
103 | * Deletes the Elasticsearch index. |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function dropIndex() |
||
111 | |||
112 | /** |
||
113 | * Puts phpMyFAQ Elasticsearch mapping into index. |
||
114 | * |
||
115 | * @return bool |
||
116 | */ |
||
117 | public function putMapping() |
||
138 | |||
139 | /** |
||
140 | * Returns the current mapping. |
||
141 | * |
||
142 | * @return array |
||
143 | */ |
||
144 | public function getMapping() |
||
148 | |||
149 | /** |
||
150 | * Indexing of a FAQ |
||
151 | * |
||
152 | * @param array $faq |
||
153 | * |
||
154 | * @return array |
||
155 | */ |
||
156 | View Code Duplication | public function index(Array $faq) |
|
174 | |||
175 | /** |
||
176 | * Bulk indexing of all FAQs |
||
177 | * |
||
178 | * @param array $faqs |
||
179 | * |
||
180 | * @return array |
||
181 | */ |
||
182 | public function bulkIndex(Array $faqs) |
||
222 | |||
223 | /** |
||
224 | * Updates a FAQ document |
||
225 | * |
||
226 | * @param array $faq |
||
227 | * @return array |
||
228 | */ |
||
229 | View Code Duplication | public function update(Array $faq) |
|
249 | |||
250 | /** |
||
251 | * Deletes a FAQ document |
||
252 | * |
||
253 | * @param integer $solutionId |
||
254 | * @return array |
||
255 | */ |
||
256 | public function delete($solutionId) |
||
266 | |||
267 | /** |
||
268 | * Returns the basic phpMyFAQ index structure as raw array. |
||
269 | * |
||
270 | * @return array |
||
271 | */ |
||
272 | private function getParams() |
||
303 | } |
||
304 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..