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 Basic extends MarkdownModuleAbstract{ |
||
16 | |||
17 | /** |
||
18 | * @var array |
||
19 | */ |
||
20 | protected $tags = ['br', 'hr', 'img', 'url']; |
||
21 | |||
22 | /** |
||
23 | * @var array |
||
24 | */ |
||
25 | protected $singletags = ['br', 'hr']; |
||
26 | |||
27 | /** |
||
28 | * @return string |
||
29 | */ |
||
30 | protected function br():string{ |
||
33 | |||
34 | /** |
||
35 | * @return string |
||
36 | */ |
||
37 | protected function hr():string{ |
||
40 | |||
41 | /** |
||
42 | * @return string |
||
43 | */ |
||
44 | protected function img():string{ // @todo: check url, alt |
||
47 | |||
48 | /** |
||
49 | * @return string |
||
50 | */ |
||
51 | View Code Duplication | protected function url():string{ // @todo linktext |
|
61 | } |
||
62 |
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.