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 |
||
| 23 | class RawScrollPaginatorAdapter implements PaginatorAdapterInterface |
||
| 24 | { |
||
| 25 | /** |
||
| 26 | * @var SearchableInterface the object to search in |
||
| 27 | */ |
||
| 28 | private $searchable; |
||
| 29 | |||
| 30 | /** |
||
| 31 | * @var Query the query to search |
||
| 32 | */ |
||
| 33 | private $query; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * @var Scroll the scroll instance |
||
| 37 | */ |
||
| 38 | private $scroll; |
||
| 39 | |||
| 40 | /** |
||
| 41 | * @var array search options |
||
| 42 | */ |
||
| 43 | private $options; |
||
| 44 | |||
| 45 | /** |
||
| 46 | * @var int the number of hits |
||
| 47 | */ |
||
| 48 | private $totalHits; |
||
| 49 | |||
| 50 | /** |
||
| 51 | * @var array for the aggregations |
||
| 52 | */ |
||
| 53 | private $aggregations; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * @var array for the suggesters |
||
| 57 | */ |
||
| 58 | private $suggests; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @var float |
||
| 62 | */ |
||
| 63 | private $maxScore; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @see PaginatorAdapterInterface::__construct |
||
| 67 | * |
||
| 68 | * @param SearchableInterface $searchable the object to search in |
||
| 69 | * @param Query $query the query to search |
||
| 70 | * @param array $options |
||
| 71 | */ |
||
| 72 | public function __construct(SearchableInterface $searchable, Query $query, array $options = []) |
||
| 78 | |||
| 79 | /** |
||
| 80 | * {@inheritdoc} |
||
| 81 | */ |
||
| 82 | public function getResults($offset, $itemCountPerPage) |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Returns the number of results. |
||
| 89 | * |
||
| 90 | * If genuineTotal is provided as true, total hits is returned from the |
||
| 91 | * hits.total value from the search results instead of just returning |
||
| 92 | * the requested size. |
||
| 93 | * |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | View Code Duplication | public function getTotalHits($genuineTotal = false) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * {@inheritdoc} |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function getAggregations() |
|
| 118 | |||
| 119 | /** |
||
| 120 | * {@inheritdoc} |
||
| 121 | */ |
||
| 122 | View Code Duplication | public function getSuggests() |
|
| 130 | |||
| 131 | /** |
||
| 132 | * @return float |
||
| 133 | */ |
||
| 134 | View Code Duplication | public function getMaxScore() |
|
| 142 | |||
| 143 | /** |
||
| 144 | * Returns the Query. |
||
| 145 | * |
||
| 146 | * @return Query the search query |
||
| 147 | */ |
||
| 148 | public function getQuery() |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Returns the paginated results. |
||
| 155 | * |
||
| 156 | * @param int $offset |
||
| 157 | * @param int $itemCountPerPage |
||
| 158 | * |
||
| 159 | * @throws \InvalidArgumentException |
||
| 160 | * |
||
| 161 | * @return ResultSet |
||
| 162 | */ |
||
| 163 | protected function getElasticaResults($offset, $itemCountPerPage) |
||
| 199 | } |
||
| 200 |