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 ReportPattern |
|
|
|||
24 | { |
||
25 | |||
26 | |||
27 | private $patterns = array(); |
||
28 | |||
29 | /** |
||
30 | * Add an extra patter object to the stack for later use |
||
31 | * |
||
32 | * @param PatternInterface $pattern |
||
33 | * @param string $alias |
||
34 | */ |
||
35 | public function addPattern(PatternInterface $pattern, $alias) |
||
39 | |||
40 | /** |
||
41 | * A front-end for running pattern operations that are loaded on to the stack |
||
42 | * |
||
43 | * @param string $alias |
||
44 | * @param ReportBuilder $context |
||
45 | * @return boolean Success condition |
||
46 | * @throws \Exception when pattern not available |
||
47 | */ |
||
48 | public function run($alias, ReportBuilder &$context) |
||
58 | |||
59 | /** |
||
60 | * Get a simple array list of the currently loaded pattern objects |
||
61 | * |
||
62 | * @return array |
||
63 | */ |
||
64 | public function getPatternsLoaded() |
||
68 | } |
||
69 |
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.