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) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Returns nested condition common for filter and query contexts. |
||
| 43 | * |
||
| 44 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
| 45 | * |
||
| 46 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 47 | * |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | protected function getCondition(Criterion $criterion) |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Map field value to a proper Elasticsearch filter representation. |
||
| 98 | * |
||
| 99 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
| 100 | * |
||
| 101 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 102 | * @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
||
| 103 | * @param array $languageFilter |
||
| 104 | * |
||
| 105 | * @return mixed |
||
| 106 | */ |
||
| 107 | View Code Duplication | public function visitFilter(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Map field value to a proper Elasticsearch query representation. |
||
| 136 | * |
||
| 137 | * @throws \eZ\Publish\Core\Base\Exceptions\InvalidArgumentException If no searchable fields are found for the given criterion target. |
||
| 138 | * |
||
| 139 | * @param \eZ\Publish\API\Repository\Values\Content\Query\Criterion $criterion |
||
| 140 | * @param \eZ\Publish\Core\Search\Elasticsearch\Content\CriterionVisitorDispatcher $dispatcher |
||
| 141 | * @param array $languageFilter |
||
| 142 | * |
||
| 143 | * @return mixed |
||
| 144 | */ |
||
| 145 | View Code Duplication | public function visitQuery(Criterion $criterion, Dispatcher $dispatcher, array $languageFilter) |
|
| 172 | } |
||
| 173 |