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:
Complex classes like Client often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Client, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
38 | class Client |
||
39 | { |
||
40 | /** |
||
41 | * Searchd host |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $host = 'localhost'; |
||
46 | |||
47 | /** |
||
48 | * Searchd port |
||
49 | * |
||
50 | * @var int |
||
51 | */ |
||
52 | protected $port = 9312; |
||
53 | |||
54 | /** |
||
55 | * How many records to seek from result-set start |
||
56 | * |
||
57 | * @var int |
||
58 | */ |
||
59 | protected $offset = 0; |
||
60 | |||
61 | /** |
||
62 | * How many records to return from result-set starting at offset |
||
63 | * |
||
64 | * @var int |
||
65 | */ |
||
66 | protected $limit = 20; |
||
67 | |||
68 | /** |
||
69 | * Query matching mode |
||
70 | * |
||
71 | * @var int |
||
72 | */ |
||
73 | protected $mode = self::MATCH_EXTENDED2; |
||
74 | |||
75 | /** |
||
76 | * Per-field weights (default is 1 for all fields) |
||
77 | * |
||
78 | * @var array |
||
79 | */ |
||
80 | protected $weights = array(); |
||
81 | |||
82 | /** |
||
83 | * Match sorting mode |
||
84 | * |
||
85 | * @var int |
||
86 | */ |
||
87 | protected $sort = self::SORT_RELEVANCE; |
||
88 | |||
89 | /** |
||
90 | * Attribute to sort by |
||
91 | * |
||
92 | * @var string |
||
93 | */ |
||
94 | protected $sort_by = ''; |
||
95 | |||
96 | /** |
||
97 | * Min ID to match (0 means no limit) |
||
98 | * |
||
99 | * @var int |
||
100 | */ |
||
101 | protected $min_id = 0; |
||
102 | |||
103 | /** |
||
104 | * Max ID to match (0 means no limit) |
||
105 | * |
||
106 | * @var int |
||
107 | */ |
||
108 | protected $max_id = 0; |
||
109 | |||
110 | /** |
||
111 | * Search filters |
||
112 | * |
||
113 | * @var array |
||
114 | */ |
||
115 | protected $filters = array(); |
||
116 | |||
117 | /** |
||
118 | * Group-by attribute name |
||
119 | * |
||
120 | * @var string |
||
121 | */ |
||
122 | protected $group_by = ''; |
||
123 | |||
124 | /** |
||
125 | * Group-by function (to pre-process group-by attribute value with) |
||
126 | * |
||
127 | * @var int |
||
128 | */ |
||
129 | protected $group_func = self::GROUP_BY_DAY; |
||
130 | |||
131 | /** |
||
132 | * Group-by sorting clause (to sort groups in result set with) |
||
133 | * |
||
134 | * @var string |
||
135 | */ |
||
136 | protected $group_sort = '@group desc'; |
||
137 | |||
138 | /** |
||
139 | * Group-by count-distinct attribute |
||
140 | * |
||
141 | * @var string |
||
142 | */ |
||
143 | protected $group_distinct = ''; |
||
144 | |||
145 | /** |
||
146 | * Max matches to retrieve |
||
147 | * |
||
148 | * @var int |
||
149 | */ |
||
150 | protected $max_matches = 1000; |
||
151 | |||
152 | /** |
||
153 | * Cutoff to stop searching at |
||
154 | * |
||
155 | * @var int |
||
156 | */ |
||
157 | protected $cutoff = 0; |
||
158 | |||
159 | /** |
||
160 | * Distributed retries count |
||
161 | * |
||
162 | * @var int |
||
163 | */ |
||
164 | protected $retry_count = 0; |
||
165 | |||
166 | /** |
||
167 | * Distributed retries delay |
||
168 | * |
||
169 | * @var int |
||
170 | */ |
||
171 | protected $retry_delay = 0; |
||
172 | |||
173 | /** |
||
174 | * Geographical anchor point |
||
175 | * |
||
176 | * @var array |
||
177 | */ |
||
178 | protected $anchor = array(); |
||
179 | |||
180 | /** |
||
181 | * Per-index weights |
||
182 | * |
||
183 | * @var array |
||
184 | */ |
||
185 | protected $index_weights = array(); |
||
186 | |||
187 | /** |
||
188 | * Ranking mode |
||
189 | * |
||
190 | * @var int |
||
191 | */ |
||
192 | protected $ranker = self::RANK_PROXIMITY_BM25; |
||
193 | |||
194 | /** |
||
195 | * Ranking mode expression (for self::RANK_EXPR) |
||
196 | * |
||
197 | * @var string |
||
198 | */ |
||
199 | protected $rank_expr = ''; |
||
200 | |||
201 | /** |
||
202 | * Max query time, milliseconds (0 means no limit) |
||
203 | * |
||
204 | * @var int |
||
205 | */ |
||
206 | protected $max_query_time = 0; |
||
207 | |||
208 | /** |
||
209 | * Per-field-name weights |
||
210 | * |
||
211 | * @var array |
||
212 | */ |
||
213 | protected $field_weights = array(); |
||
214 | |||
215 | /** |
||
216 | * Per-query attribute values overrides |
||
217 | * |
||
218 | * @var array |
||
219 | */ |
||
220 | protected $overrides = array(); |
||
221 | |||
222 | /** |
||
223 | * Select-list (attributes or expressions, with optional aliases) |
||
224 | * |
||
225 | * @var string |
||
226 | */ |
||
227 | protected $select = '*'; |
||
228 | |||
229 | /** |
||
230 | * Per-query various flags |
||
231 | * |
||
232 | * @var int |
||
233 | */ |
||
234 | protected $query_flags = 0; |
||
235 | |||
236 | /** |
||
237 | * Per-query max_predicted_time |
||
238 | * |
||
239 | * @var int |
||
240 | */ |
||
241 | protected $predicted_time = 0; |
||
242 | |||
243 | /** |
||
244 | * Outer match sort by |
||
245 | * |
||
246 | * @var string |
||
247 | */ |
||
248 | protected $outer_order_by = ''; |
||
249 | |||
250 | /** |
||
251 | * Outer offset |
||
252 | * |
||
253 | * @var int |
||
254 | */ |
||
255 | protected $outer_offset = 0; |
||
256 | |||
257 | /** |
||
258 | * Outer limit |
||
259 | * |
||
260 | * @var int |
||
261 | */ |
||
262 | protected $outer_limit = 0; |
||
263 | |||
264 | /** |
||
265 | * @var bool |
||
266 | */ |
||
267 | protected $has_outer = false; |
||
268 | |||
269 | /** |
||
270 | * Last error message |
||
271 | * |
||
272 | * @var string |
||
273 | */ |
||
274 | protected $error = ''; |
||
275 | |||
276 | /** |
||
277 | * Last warning message |
||
278 | * |
||
279 | * @var string |
||
280 | */ |
||
281 | protected $warning = ''; |
||
282 | |||
283 | /** |
||
284 | * Connection error vs remote error flag |
||
285 | * |
||
286 | * @var bool |
||
287 | */ |
||
288 | protected $conn_error = false; |
||
289 | |||
290 | /** |
||
291 | * Requests array for multi-query |
||
292 | * |
||
293 | * @var array |
||
294 | */ |
||
295 | protected $reqs = array(); |
||
296 | |||
297 | /** |
||
298 | * Stored mbstring encoding |
||
299 | * |
||
300 | * @var string |
||
301 | */ |
||
302 | protected $mbenc = ''; |
||
303 | |||
304 | /** |
||
305 | * Whether $result['matches'] should be a hash or an array |
||
306 | * |
||
307 | * @var bool |
||
308 | */ |
||
309 | protected $array_result = false; |
||
310 | |||
311 | /** |
||
312 | * Connect timeout |
||
313 | * |
||
314 | * @var int|float |
||
315 | */ |
||
316 | protected $timeout = 0; |
||
317 | |||
318 | /** |
||
319 | * @var string |
||
320 | */ |
||
321 | protected $path = ''; |
||
322 | |||
323 | /** |
||
324 | * @var resource|bool |
||
325 | */ |
||
326 | protected $socket = false; |
||
327 | |||
328 | // known searchd commands |
||
329 | const SEARCHD_COMMAND_SEARCH = 0; |
||
330 | const SEARCHD_COMMAND_EXCERPT = 1; |
||
331 | const SEARCHD_COMMAND_UPDATE = 2; |
||
332 | const SEARCHD_COMMAND_KEYWORDS = 3; |
||
333 | const SEARCHD_COMMAND_PERSIST = 4; |
||
334 | const SEARCHD_COMMAND_STATUS = 5; |
||
335 | const SEARCHD_COMMAND_FLUSH_ATTRS = 7; |
||
336 | |||
337 | // current client-side command implementation versions |
||
338 | const VER_COMMAND_SEARCH = 0x11E; |
||
339 | const VER_COMMAND_EXCERPT = 0x104; |
||
340 | const VER_COMMAND_UPDATE = 0x103; |
||
341 | const VER_COMMAND_KEYWORDS = 0x100; |
||
342 | const VER_COMMAND_STATUS = 0x101; |
||
343 | const VER_COMMAND_QUERY = 0x100; |
||
344 | const VER_COMMAND_FLUSH_ATTRS = 0x100; |
||
345 | |||
346 | // known searchd status codes |
||
347 | const SEARCHD_OK = 0; |
||
348 | const SEARCHD_ERROR = 1; |
||
349 | const SEARCHD_RETRY = 2; |
||
350 | const SEARCHD_WARNING = 3; |
||
351 | |||
352 | // known match modes |
||
353 | const MATCH_ALL = 0; |
||
354 | const MATCH_ANY = 1; |
||
355 | const MATCH_PHRASE = 2; |
||
356 | const MATCH_BOOLEAN = 3; |
||
357 | const MATCH_EXTENDED = 4; |
||
358 | const MATCH_FULL_SCAN = 5; |
||
359 | const MATCH_EXTENDED2 = 6; // extended engine V2 (TEMPORARY, WILL BE REMOVED) |
||
360 | |||
361 | // known ranking modes (ext2 only) |
||
362 | const RANK_PROXIMITY_BM25 = 0; // default mode, phrase proximity major factor and BM25 minor one |
||
363 | const RANK_BM25 = 1; // statistical mode, BM25 ranking only (faster but worse quality) |
||
364 | const RANK_NONE = 2; // no ranking, all matches get a weight of 1 |
||
365 | const RANK_WORD_COUNT = 3; // simple word-count weighting, rank is a weighted sum of per-field keyword |
||
366 | // occurrence counts |
||
367 | const RANK_PROXIMITY = 4; |
||
368 | const RANK_MATCH_ANY = 5; |
||
369 | const RANK_FIELD_MASK = 6; |
||
370 | const RANK_SPH04 = 7; |
||
371 | const RANK_EXPR = 8; |
||
372 | const RANK_TOTAL = 9; |
||
373 | |||
374 | // known sort modes |
||
375 | const SORT_RELEVANCE = 0; |
||
376 | const SORT_ATTR_DESC = 1; |
||
377 | const SORT_ATTR_ASC = 2; |
||
378 | const SORT_TIME_SEGMENTS = 3; |
||
379 | const SORT_EXTENDED = 4; |
||
380 | const SORT_EXPR = 5; |
||
381 | |||
382 | // known filter types |
||
383 | const FILTER_VALUES = 0; |
||
384 | const FILTER_RANGE = 1; |
||
385 | const FILTER_FLOAT_RANGE = 2; |
||
386 | const FILTER_STRING = 3; |
||
387 | |||
388 | // known attribute types |
||
389 | const ATTR_INTEGER = 1; |
||
390 | const ATTR_TIMESTAMP = 2; |
||
391 | const ATTR_ORDINAL = 3; |
||
392 | const ATTR_BOOL = 4; |
||
393 | const ATTR_FLOAT = 5; |
||
394 | const ATTR_BIGINT = 6; |
||
395 | const ATTR_STRING = 7; |
||
396 | const ATTR_FACTORS = 1001; |
||
397 | const ATTR_MULTI = 0x40000001; |
||
398 | const ATTR_MULTI64 = 0x40000002; |
||
399 | |||
400 | // known grouping functions |
||
401 | const GROUP_BY_DAY = 0; |
||
402 | const GROUP_BY_WEEK = 1; |
||
403 | const GROUP_BY_MONTH = 2; |
||
404 | const GROUP_BY_YEAR = 3; |
||
405 | const GROUP_BY_ATTR = 4; |
||
406 | const GROUP_BY_ATTR_PAIR = 5; |
||
407 | |||
408 | ///////////////////////////////////////////////////////////////////////////// |
||
409 | // common stuff |
||
410 | ///////////////////////////////////////////////////////////////////////////// |
||
411 | |||
412 | 4 | public function __construct() |
|
417 | |||
418 | public function __destruct() |
||
424 | |||
425 | /** |
||
426 | * @return string |
||
427 | */ |
||
428 | 1 | public function getLastError() |
|
432 | |||
433 | /** |
||
434 | * @return string |
||
435 | */ |
||
436 | 1 | public function getLastWarning() |
|
440 | |||
441 | /** |
||
442 | * Get last error flag (to tell network connection errors from searchd errors or broken responses) |
||
443 | * |
||
444 | * @return bool |
||
445 | */ |
||
446 | 1 | public function isConnectError() |
|
450 | |||
451 | /** |
||
452 | * Set searchd host name and port |
||
453 | * |
||
454 | * @param string $host |
||
455 | * @param int $port |
||
456 | */ |
||
457 | public function setServer($host, $port = 0) |
||
475 | |||
476 | /** |
||
477 | * Set server connection timeout (0 to remove) |
||
478 | * |
||
479 | * @param int|float|string $timeout |
||
480 | */ |
||
481 | public function setConnectTimeout($timeout) |
||
486 | |||
487 | /** |
||
488 | * @param resource $handle |
||
489 | * @param string $data |
||
490 | * @param int $length |
||
491 | * |
||
492 | * @return bool |
||
493 | */ |
||
494 | protected function send($handle, $data, $length) |
||
503 | |||
504 | ///////////////////////////////////////////////////////////////////////////// |
||
505 | |||
506 | /** |
||
507 | * Enter mbstring workaround mode |
||
508 | */ |
||
509 | protected function mbPush() |
||
517 | |||
518 | /** |
||
519 | * Leave mbstring workaround mode |
||
520 | */ |
||
521 | protected function mbPop() |
||
527 | |||
528 | /** |
||
529 | * Connect to searchd server |
||
530 | * |
||
531 | * @return bool|resource |
||
532 | */ |
||
533 | protected function connect() |
||
598 | |||
599 | /** |
||
600 | * Get and check response packet from searchd server |
||
601 | * |
||
602 | * @param resource $fp |
||
603 | * @param int $client_ver |
||
604 | * |
||
605 | * @return bool|string |
||
606 | */ |
||
607 | protected function getResponse($fp, $client_ver) |
||
670 | |||
671 | ///////////////////////////////////////////////////////////////////////////// |
||
672 | // searching |
||
673 | ///////////////////////////////////////////////////////////////////////////// |
||
674 | |||
675 | /** |
||
676 | * Set offset and count into result set, and optionally set max-matches and cutoff limits |
||
677 | * |
||
678 | * @param int $offset |
||
679 | * @param int $limit |
||
680 | * @param int $max |
||
681 | * @param int $cutoff |
||
682 | */ |
||
683 | public function setLimits($offset, $limit, $max = 0, $cutoff = 0) |
||
699 | |||
700 | /** |
||
701 | * Set maximum query time, in milliseconds, per-index, 0 means 'do not limit' |
||
702 | * |
||
703 | * @param int $max |
||
704 | */ |
||
705 | public function setMaxQueryTime($max) |
||
711 | |||
712 | /** |
||
713 | * Set matching mode |
||
714 | * |
||
715 | * @param int $mode |
||
716 | */ |
||
717 | public function setMatchMode($mode) |
||
734 | |||
735 | /** |
||
736 | * Set ranking mode |
||
737 | * |
||
738 | * @param int $ranker |
||
739 | * @param string $rank_expr |
||
740 | */ |
||
741 | public function setRankingMode($ranker, $rank_expr='') |
||
748 | |||
749 | /** |
||
750 | * Set matches sorting mode |
||
751 | * |
||
752 | * @param int $mode |
||
753 | * @param string $sort_by |
||
754 | */ |
||
755 | public function setSortMode($mode, $sort_by = '') |
||
771 | |||
772 | /** |
||
773 | * Bind per-field weights by order |
||
774 | * |
||
775 | * @deprecated use setFieldWeights() instead |
||
776 | */ |
||
777 | 1 | public function setWeights() |
|
781 | |||
782 | /** |
||
783 | * Bind per-field weights by name |
||
784 | * |
||
785 | * @param array $weights |
||
786 | */ |
||
787 | public function setFieldWeights(array $weights) |
||
795 | |||
796 | /** |
||
797 | * Bind per-index weights by name |
||
798 | * |
||
799 | * @param array $weights |
||
800 | */ |
||
801 | public function setIndexWeights(array $weights) |
||
809 | |||
810 | /** |
||
811 | * Set IDs range to match. Only match records if document ID is beetwen $min and $max (inclusive) |
||
812 | * |
||
813 | * @param int $min |
||
814 | * @param int $max |
||
815 | */ |
||
816 | public function setIDRange($min, $max) |
||
825 | |||
826 | /** |
||
827 | * Set values set filter. Only match records where $attribute value is in given set |
||
828 | * |
||
829 | * @param string $attribute |
||
830 | * @param array $values |
||
831 | * @param bool $exclude |
||
832 | */ |
||
833 | public function setFilter($attribute, array $values, $exclude = false) |
||
849 | |||
850 | /** |
||
851 | * Set string filter |
||
852 | * Only match records where $attribute value is equal |
||
853 | * |
||
854 | * @param string $attribute |
||
855 | * @param string $value |
||
856 | * @param bool $exclude |
||
857 | */ |
||
858 | public function setFilterString($attribute, $value, $exclude = false) |
||
869 | |||
870 | /** |
||
871 | * Set range filter |
||
872 | * Only match records if $attribute value is beetwen $min and $max (inclusive) |
||
873 | * |
||
874 | * @param string $attribute |
||
875 | * @param int $min |
||
876 | * @param int $max |
||
877 | * @param bool $exclude |
||
878 | */ |
||
879 | public function setFilterRange($attribute, $min, $max, $exclude = false) |
||
894 | |||
895 | /** |
||
896 | * Set float range filter |
||
897 | * Only match records if $attribute value is beetwen $min and $max (inclusive) |
||
898 | * |
||
899 | * @param string $attribute |
||
900 | * @param float $min |
||
901 | * @param float $max |
||
902 | * @param bool $exclude |
||
903 | */ |
||
904 | public function setFilterFloatRange($attribute, $min, $max, $exclude = false) |
||
919 | |||
920 | /** |
||
921 | * Setup anchor point for geosphere distance calculations |
||
922 | * Required to use @geodist in filters and sorting |
||
923 | * Latitude and longitude must be in radians |
||
924 | * |
||
925 | * @param string $attr_lat |
||
926 | * @param string $attr_long |
||
927 | * @param float $lat |
||
928 | * @param float $long |
||
929 | */ |
||
930 | public function setGeoAnchor($attr_lat, $attr_long, $lat, $long) |
||
944 | |||
945 | /** |
||
946 | * Set grouping attribute and function |
||
947 | * |
||
948 | * @param string $attribute |
||
949 | * @param int $func |
||
950 | * @param string $group_sort |
||
951 | */ |
||
952 | public function setGroupBy($attribute, $func, $group_sort = '@group desc') |
||
969 | |||
970 | /** |
||
971 | * Set count-distinct attribute for group-by queries |
||
972 | * |
||
973 | * @param string $attribute |
||
974 | */ |
||
975 | public function setGroupDistinct($attribute) |
||
980 | |||
981 | /** |
||
982 | * Set distributed retries count and delay |
||
983 | * |
||
984 | * @param int $count |
||
985 | * @param int $delay |
||
986 | */ |
||
987 | public function setRetries($count, $delay = 0) |
||
994 | |||
995 | /** |
||
996 | * Set result set format (hash or array; hash by default) |
||
997 | * PHP specific; needed for group-by-MVA result sets that may contain duplicate IDs |
||
998 | * |
||
999 | * @param bool $array_result |
||
1000 | */ |
||
1001 | public function setArrayResult($array_result) |
||
1006 | |||
1007 | /** |
||
1008 | * Set attribute values override |
||
1009 | * There can be only one override per attribute |
||
1010 | * $values must be a hash that maps document IDs to attribute values |
||
1011 | * |
||
1012 | * @deprecated Do not call this method. Use SphinxQL REMAP() function instead. |
||
1013 | * |
||
1014 | * @param string $attr_name |
||
1015 | * @param string $attr_type |
||
1016 | * @param array $values |
||
1017 | */ |
||
1018 | public function setOverride($attr_name, $attr_type, array $values) |
||
1039 | |||
1040 | /** |
||
1041 | * Set select-list (attributes or expressions), SQL-like syntax |
||
1042 | * |
||
1043 | * @param string $select |
||
1044 | */ |
||
1045 | public function setSelect($select) |
||
1050 | |||
1051 | /** |
||
1052 | * @param string $flag_name |
||
1053 | * @param string|int $flag_value |
||
1054 | */ |
||
1055 | public function setQueryFlag($flag_name, $flag_value) |
||
1112 | |||
1113 | /** |
||
1114 | * Set outer order by parameters |
||
1115 | * |
||
1116 | * @param string $order_by |
||
1117 | * @param int $offset |
||
1118 | * @param int $limit |
||
1119 | */ |
||
1120 | public function setOuterSelect($order_by, $offset, $limit) |
||
1133 | |||
1134 | |||
1135 | ////////////////////////////////////////////////////////////////////////////// |
||
1136 | |||
1137 | /** |
||
1138 | * Clear all filters (for multi-queries) |
||
1139 | */ |
||
1140 | public function resetFilters() |
||
1145 | |||
1146 | /** |
||
1147 | * Clear groupby settings (for multi-queries) |
||
1148 | */ |
||
1149 | public function resetGroupBy() |
||
1156 | |||
1157 | /** |
||
1158 | * Clear all attribute value overrides (for multi-queries) |
||
1159 | */ |
||
1160 | public function resetOverrides() |
||
1164 | |||
1165 | public function resetQueryFlag() |
||
1170 | |||
1171 | public function resetOuterSelect() |
||
1178 | |||
1179 | ////////////////////////////////////////////////////////////////////////////// |
||
1180 | |||
1181 | /** |
||
1182 | * Connect to searchd server, run given search query through given indexes, and return the search results |
||
1183 | * |
||
1184 | * @param string $query |
||
1185 | * @param string $index |
||
1186 | * @param string $comment |
||
1187 | * |
||
1188 | * @return bool |
||
1189 | */ |
||
1190 | public function query($query, $index = '*', $comment = '') |
||
1211 | |||
1212 | /** |
||
1213 | * Helper to pack floats in network byte order |
||
1214 | * |
||
1215 | * @param float $float |
||
1216 | * |
||
1217 | * @return string |
||
1218 | */ |
||
1219 | protected function packFloat($float) |
||
1225 | |||
1226 | /** |
||
1227 | * Add query to multi-query batch |
||
1228 | * Returns index into results array from RunQueries() call |
||
1229 | * |
||
1230 | * @param string $query |
||
1231 | * @param string $index |
||
1232 | * @param string $comment |
||
1233 | * |
||
1234 | * @return int |
||
1235 | */ |
||
1236 | public function addQuery($query, $index = '*', $comment = '') |
||
1367 | |||
1368 | /** |
||
1369 | * Connect to searchd, run queries batch, and return an array of result sets |
||
1370 | * |
||
1371 | * @return array|bool |
||
1372 | */ |
||
1373 | public function runQueries() |
||
1406 | |||
1407 | /** |
||
1408 | * Parse and return search query (or queries) response |
||
1409 | * |
||
1410 | * @param string $response |
||
1411 | * @param int $nreqs |
||
1412 | * |
||
1413 | * @return array |
||
1414 | */ |
||
1415 | protected function parseSearchResponse($response, $nreqs) |
||
1584 | |||
1585 | ///////////////////////////////////////////////////////////////////////////// |
||
1586 | // excerpts generation |
||
1587 | ///////////////////////////////////////////////////////////////////////////// |
||
1588 | |||
1589 | /** |
||
1590 | * Connect to searchd server, and generate exceprts (snippets) of given documents for given query. |
||
1591 | * Returns false on failure, an array of snippets on success |
||
1592 | * |
||
1593 | * @param array $docs |
||
1594 | * @param string $index |
||
1595 | * @param string $words |
||
1596 | * @param array $opts |
||
1597 | * |
||
1598 | * @return array|bool |
||
1599 | */ |
||
1600 | public function buildExcerpts(array $docs, $index, $words, array $opts = array()) |
||
1731 | |||
1732 | |||
1733 | ///////////////////////////////////////////////////////////////////////////// |
||
1734 | // keyword generation |
||
1735 | ///////////////////////////////////////////////////////////////////////////// |
||
1736 | |||
1737 | /** |
||
1738 | * Connect to searchd server, and generate keyword list for a given query returns false on failure, |
||
1739 | * an array of words on success |
||
1740 | * |
||
1741 | * @param string $query |
||
1742 | * @param string $index |
||
1743 | * @param bool $hits |
||
1744 | * |
||
1745 | * @return array|bool |
||
1746 | */ |
||
1747 | public function buildKeywords($query, $index, $hits) |
||
1822 | |||
1823 | /** |
||
1824 | * @param string $string |
||
1825 | * |
||
1826 | * @return string |
||
1827 | */ |
||
1828 | public function escapeString($string) |
||
1835 | |||
1836 | ///////////////////////////////////////////////////////////////////////////// |
||
1837 | // attribute updates |
||
1838 | ///////////////////////////////////////////////////////////////////////////// |
||
1839 | |||
1840 | /** |
||
1841 | * Batch update given attributes in given rows in given indexes |
||
1842 | * Returns amount of updated documents (0 or more) on success, or -1 on failure |
||
1843 | * |
||
1844 | * @param string $index |
||
1845 | * @param array $attrs |
||
1846 | * @param array $values |
||
1847 | * @param bool $mva |
||
1848 | * @param bool $ignore_non_existent |
||
1849 | * |
||
1850 | * @return int |
||
1851 | */ |
||
1852 | public function updateAttributes($index, array $attrs, array $values, $mva = false, $ignore_non_existent = false) |
||
1926 | |||
1927 | ///////////////////////////////////////////////////////////////////////////// |
||
1928 | // persistent connections |
||
1929 | ///////////////////////////////////////////////////////////////////////////// |
||
1930 | |||
1931 | /** |
||
1932 | * @return bool |
||
1933 | */ |
||
1934 | public function open() |
||
1952 | |||
1953 | /** |
||
1954 | * @return bool |
||
1955 | */ |
||
1956 | public function close() |
||
1968 | |||
1969 | ////////////////////////////////////////////////////////////////////////// |
||
1970 | // status |
||
1971 | ////////////////////////////////////////////////////////////////////////// |
||
1972 | |||
1973 | /** |
||
1974 | * @param bool $session |
||
1975 | * |
||
1976 | * @return array|bool |
||
1977 | */ |
||
1978 | public function status($session = false) |
||
2013 | |||
2014 | ////////////////////////////////////////////////////////////////////////// |
||
2015 | // flush |
||
2016 | ////////////////////////////////////////////////////////////////////////// |
||
2017 | |||
2018 | /** |
||
2019 | * @return int |
||
2020 | */ |
||
2021 | public function flushAttributes() |
||
2045 | } |
||
2046 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.