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 |
||
15 | class Bar extends Renderer |
||
16 | { |
||
17 | /** |
||
18 | * @var ProfilerInterface |
||
19 | */ |
||
20 | protected $profiler; |
||
21 | |||
22 | /** |
||
23 | * Process constructor. |
||
24 | */ |
||
25 | 16 | public function __construct(array $profile, ProfilerInterface $profiler) |
|
31 | |||
32 | |||
33 | /** |
||
34 | * @return mixed |
||
35 | */ |
||
36 | 16 | public function getTemplate() |
|
40 | |||
41 | /** |
||
42 | * @return mixed |
||
43 | */ |
||
44 | 16 | public function getData() |
|
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | 16 | public function getIcon() |
|
90 | |||
91 | /** |
||
92 | * @return string |
||
93 | */ |
||
94 | 16 | public function getTitle() |
|
98 | } |
||
99 |
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.