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 |
||
22 | View Code Duplication | class DisMaxQuery implements BuilderInterface |
|
|
|||
23 | { |
||
24 | use ParametersTrait; |
||
25 | |||
26 | /** |
||
27 | * @var BuilderInterface[] |
||
28 | */ |
||
29 | private $queries = []; |
||
30 | |||
31 | /** |
||
32 | * Initializes Dis Max query. |
||
33 | * |
||
34 | * @param array $parameters |
||
35 | */ |
||
36 | public function __construct(array $parameters = []) |
||
40 | |||
41 | /** |
||
42 | * Add query. |
||
43 | * |
||
44 | * @param BuilderInterface $query |
||
45 | * |
||
46 | * @return DisMaxQuery |
||
47 | */ |
||
48 | public function addQuery(BuilderInterface $query) |
||
54 | |||
55 | /** |
||
56 | * {@inheritdoc} |
||
57 | */ |
||
58 | public function getType() |
||
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | public function toArray() |
||
76 | } |
||
77 |
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.