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 FuzzySearch extends AbstractSingleValue |
||
24 | { |
||
25 | /** |
||
26 | * @var array Fuzzy query parameters. |
||
27 | */ |
||
28 | private $parameters = []; |
||
29 | |||
30 | /** |
||
31 | * {@inheritdoc} |
||
32 | */ |
||
33 | View Code Duplication | public function modifySearch(Search $search, FilterState $state = null, SearchRequest $request = null) |
|
50 | |||
51 | /** |
||
52 | * @return array |
||
53 | */ |
||
54 | public function getParameters() |
||
58 | |||
59 | /** |
||
60 | * The maximum edit distance. |
||
61 | * |
||
62 | * @param string|int|float $fuzziness |
||
63 | */ |
||
64 | public function setFuzziness($fuzziness) |
||
68 | |||
69 | /** |
||
70 | * The number of initial characters which will not be “fuzzified”. |
||
71 | * |
||
72 | * @param int $prefixLength |
||
73 | */ |
||
74 | public function setPrefixLength($prefixLength) |
||
78 | |||
79 | /** |
||
80 | * The maximum number of terms that the fuzzy query will expand to. |
||
81 | * |
||
82 | * @param int $maxExpansions |
||
83 | */ |
||
84 | public function setMaxExpansions($maxExpansions) |
||
88 | } |
||
89 |
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.