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 MatchSearch extends AbstractSingleValue |
||
24 | { |
||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | private $parameters = []; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
||
47 | |||
48 | /** |
||
49 | * Build possibly nested match part. |
||
50 | * |
||
51 | * @param string $field |
||
52 | * @param FilterState $state |
||
53 | * |
||
54 | * @return BuilderInterface |
||
55 | */ |
||
56 | private function buildMatchPart($field, FilterState $state) |
||
75 | |||
76 | /** |
||
77 | * Sets operator |
||
78 | * |
||
79 | * @param string $operator |
||
80 | */ |
||
81 | public function setOperator($operator) |
||
85 | |||
86 | /** |
||
87 | * Sets the maximum edit distance |
||
88 | * |
||
89 | * @param string|int|float $fuzziness |
||
90 | */ |
||
91 | public function setFuzziness($fuzziness) |
||
95 | } |
||
96 |
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.