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 |
||
11 | View Code Duplication | class ClassDecorator extends AbstractCellDecorator |
|
|
|||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Class |
||
16 | * @var array |
||
17 | */ |
||
18 | protected $class; |
||
19 | |||
20 | public function __construct($options) |
||
24 | |||
25 | /** |
||
26 | * Rendering decorator |
||
27 | * |
||
28 | * @param string $context |
||
29 | * @return string |
||
30 | */ |
||
31 | public function render($context) |
||
40 | |||
41 | /** |
||
42 | * Set class |
||
43 | * |
||
44 | * @param string $class |
||
45 | * @return $this |
||
46 | */ |
||
47 | public function setClass($class) |
||
52 | |||
53 | /** |
||
54 | * Get class |
||
55 | * |
||
56 | * @return null|array |
||
57 | */ |
||
58 | public function getClass() |
||
62 | } |
||
63 |
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.