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 ReportQuery |
|
|
|||
23 | { |
||
24 | |||
25 | |||
26 | private $queries = array(); |
||
27 | |||
28 | /** |
||
29 | * Add an extra patter object to the stack for later use |
||
30 | * |
||
31 | * @param QueryInterface $query |
||
32 | * @param string $alias |
||
33 | */ |
||
34 | public function addQuery(QueryInterface $query, $alias) |
||
38 | |||
39 | /** |
||
40 | * A front-end for running pattern operations that are loaded on to the stack |
||
41 | * |
||
42 | * @param string $alias |
||
43 | * @param ReportBuilder $context |
||
44 | * @return boolean Success condition |
||
45 | * @throws \Exception when pattern not available |
||
46 | */ |
||
47 | public function get($alias) |
||
56 | |||
57 | /** |
||
58 | * Get a simple array list of the currently loaded pattern objects |
||
59 | * |
||
60 | * @return array |
||
61 | */ |
||
62 | public function getQueriesLoaded() |
||
66 | } |
||
67 |
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.