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 |
||
| 13 | class SpanNear extends AbstractSpanQuery |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Constructs a SpanNear query object. |
||
| 17 | * |
||
| 18 | * @param AbstractSpanQuery[] $clauses OPTIONAL |
||
| 19 | * @param int $slop OPTIONAL maximum proximity |
||
| 20 | * @param bool $inOrder OPTIONAL true if order of searched clauses is important |
||
| 21 | */ |
||
| 22 | public function __construct($clauses = [], $slop = 1, $inOrder = false) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @param int $slop |
||
| 40 | */ |
||
| 41 | public function setSlop($slop) |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @param bool $inOrder |
||
| 48 | */ |
||
| 49 | public function setInOrder($inOrder) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Add clause part to query. |
||
| 56 | * |
||
| 57 | * @param AbstractSpanQuery $clause |
||
| 58 | * |
||
| 59 | * @throws InvalidException If not valid query |
||
| 60 | * |
||
| 61 | * @return $this |
||
| 62 | */ |
||
| 63 | View Code Duplication | public function addClause($clause) |
|
| 71 | } |
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.