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 |
||
| 12 | View Code Duplication | class SpanTerm extends AbstractSpanQuery |
|
|
|
|||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Constructs the SpanTerm query object. |
||
| 16 | * |
||
| 17 | * @param array $term OPTIONAL Calls setRawTerm with the given $term array |
||
| 18 | */ |
||
| 19 | public function __construct(array $term = []) |
||
| 23 | |||
| 24 | /** |
||
| 25 | * Set term can be used instead of setTerm if some more special |
||
| 26 | * values for a term have to be set. |
||
| 27 | * |
||
| 28 | * @param array $term Term array |
||
| 29 | * |
||
| 30 | * @return $this |
||
| 31 | */ |
||
| 32 | public function setRawTerm(array $term) |
||
| 36 | |||
| 37 | /** |
||
| 38 | * Adds a term to the term query. |
||
| 39 | * |
||
| 40 | * @param string $key Key to query |
||
| 41 | * @param string|array $value Values(s) for the query. Boost can be set with array |
||
| 42 | * @param float $boost OPTIONAL Boost value (default = 1.0) |
||
| 43 | * |
||
| 44 | * @return $this |
||
| 45 | */ |
||
| 46 | public function setTerm($key, $value, $boost = 1.0) |
||
| 50 | } |
||
| 51 |
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.