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 |
||
20 | class FieldIn extends Field |
||
21 | { |
||
22 | /** |
||
23 | * Check if visitor is applicable to current criterion. |
||
24 | * |
||
25 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
26 | * |
||
27 | * @return bool |
||
28 | */ |
||
29 | public function canVisit(Criterion $criterion) |
||
39 | |||
40 | /** |
||
41 | * Returns nested condition common for filter and query contexts. |
||
42 | * |
||
43 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
44 | * |
||
45 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | protected function getCondition(Criterion $criterion) |
||
84 | |||
85 | /** |
||
86 | * Map field value to a proper Elasticsearch filter representation. |
||
87 | * |
||
88 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
89 | * |
||
90 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
91 | * @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
||
92 | * @param array $languageFilter |
||
93 | * |
||
94 | * @return mixed |
||
95 | */ |
||
96 | View Code Duplication | public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
|
122 | |||
123 | /** |
||
124 | * Map field value to a proper Elasticsearch query representation. |
||
125 | * |
||
126 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
127 | * |
||
128 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
129 | * @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
||
130 | * @param array $languageFilter |
||
131 | * |
||
132 | * @return mixed |
||
133 | */ |
||
134 | View Code Duplication | public function visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
|
161 | } |
||
162 |