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 |
||
| 14 | class SpanMulti extends AbstractSpanQuery |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * Constructs a SpanMulti query object. |
||
| 18 | * |
||
| 19 | * @param \Elastica\Query\AbstractQuery|array $match OPTIONAL |
||
| 20 | */ |
||
| 21 | public function __construct($match = null) |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Set the query to be wrapped into the span multi query. |
||
| 30 | * |
||
| 31 | * @param \Elastica\Query\AbstractQuery|array $args Matching query |
||
| 32 | * |
||
| 33 | * @return $this |
||
| 34 | */ |
||
| 35 | public function setMatch($args) |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Sets a query to the current object. |
||
| 42 | * |
||
| 43 | * @param string $type Query type |
||
| 44 | * @param \Elastica\Query\AbstractQuery|array $args Query |
||
| 45 | * |
||
| 46 | * @throws \Elastica\Exception\InvalidException If not valid query |
||
| 47 | * |
||
| 48 | * @return $this |
||
| 49 | */ |
||
| 50 | View Code Duplication | protected function _setQuery($type, $args) |
|
| 58 | } |
||
| 59 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.