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 |
||
6 | class Where |
||
7 | { |
||
8 | protected $field; |
||
9 | |||
10 | protected $query; |
||
11 | |||
12 | |||
13 | public function __construct(SearchQuery $query) |
||
17 | |||
18 | /** |
||
19 | * @param mixed $field |
||
20 | */ |
||
21 | public function setField($field) |
||
25 | |||
26 | /** |
||
27 | * @param $value |
||
28 | * @return SearchQuery |
||
29 | */ |
||
30 | public function equal($value) |
||
35 | |||
36 | /** |
||
37 | * Добавить фильтр совпадения хотя бы одного значения из набора, этот фильтр не влияет на поле релевантности _score. |
||
38 | * |
||
39 | * @param $values - массив допустимых значений |
||
40 | * @example $query->where('channel')->in([1,2,3])->where('page.categoryId')->in([10,11]); |
||
41 | * @return SearchQuery; |
||
|
|||
42 | */ |
||
43 | public function in(array $values) |
||
50 | |||
51 | /** |
||
52 | * Добавить фильтр вхождения значение в диапазон (обе границы включительно). |
||
53 | * Можно искать по диапазону дат. |
||
54 | * Этот фильтр не влияет на поле релевантности _score. |
||
55 | * |
||
56 | * @param $min - нижняя граница диапазона (включительно) |
||
57 | * @param $max - верхняя граница диапазона (включительно) |
||
58 | * @param $dateFormat - необязательное поле описание формата даты |
||
59 | * @link https://www.elastic.co/guide/en/elasticsearch/reference/5.0/query-dsl-range-query.html |
||
60 | * @return SearchQuery; |
||
61 | */ |
||
62 | View Code Duplication | public function between($min, $max, $dateFormat = null) |
|
71 | |||
72 | /** |
||
73 | * Добавить фильтр "больше или равно" |
||
74 | * @param $value - значение |
||
75 | * @param null $dateFormat - необязательный формат даты |
||
76 | * @return SearchQuery |
||
77 | */ |
||
78 | View Code Duplication | public function greaterOrEqual($value, $dateFormat = null) |
|
87 | |||
88 | /** |
||
89 | * Добавить фильтр "больше чем" |
||
90 | * @param $value - значение |
||
91 | * @param null $dateFormat - необязательный формат даты |
||
92 | * @return SearchQuery |
||
93 | */ |
||
94 | View Code Duplication | public function greater($value, $dateFormat = null) |
|
103 | |||
104 | /** |
||
105 | * Добавить фильтр "меньше или равно" |
||
106 | * @param $value - значение |
||
107 | * @param null $dateFormat - необязательный формат даты |
||
108 | * @return SearchQuery |
||
109 | */ |
||
110 | View Code Duplication | public function lessOrEqual($value, $dateFormat = null) |
|
119 | |||
120 | |||
121 | /** |
||
122 | * Добавить фильтр "меньше чем" |
||
123 | * @param $value - значение |
||
124 | * @param null $dateFormat - - необязательный формат даты |
||
125 | * @return SearchQuery |
||
126 | */ |
||
127 | View Code Duplication | public function less($value, $dateFormat = null) |
|
136 | |||
137 | |||
138 | /** |
||
139 | * Добавить фильтр полнотекстового поиска, этот фильтр влияет на поле релевантности _score. |
||
140 | * |
||
141 | * @param $text - поисковая фраза |
||
142 | * @return SearchQuery; |
||
143 | */ |
||
144 | public function match($text) |
||
156 | |||
157 | } |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.