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 | View Code Duplication | class ReportStyle |
|
|
|||
24 | { |
||
25 | private $styles = array(); |
||
26 | |||
27 | /** |
||
28 | * Add an extra styler object to the stack for later use |
||
29 | * |
||
30 | * @param StyleInterface $style |
||
31 | * @param string $alias |
||
32 | */ |
||
33 | public function addStyle(StyleInterface $style, $alias) |
||
37 | |||
38 | /** |
||
39 | * A front-end for running style operations that are loaded on to the stack |
||
40 | * |
||
41 | * @param string $alias |
||
42 | * @param ReportBuilder $context |
||
43 | * @param string $coordString |
||
44 | * @param array $options |
||
45 | * @return boolean Success condition |
||
46 | * @throws \Exception when style function not available |
||
47 | */ |
||
48 | public function run($alias, ReportBuilder &$context, $coordString, $options = array()) |
||
59 | |||
60 | /** |
||
61 | * Get a simple array list of the currently loaded style objects |
||
62 | * |
||
63 | * @return array |
||
64 | */ |
||
65 | public function getStylesLoaded() |
||
69 | } |
||
70 |
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.