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 |
||
8 | class PointParser extends MarkdownParser |
||
9 | { |
||
10 | /** |
||
11 | * @var RouterInterface |
||
12 | */ |
||
13 | protected $router; |
||
14 | |||
15 | /** |
||
16 | * {@inheritdoc} |
||
17 | */ |
||
18 | protected $features = array( |
||
19 | 'header' => true, |
||
20 | 'list' => true, |
||
21 | 'horizontal_rule' => true, |
||
22 | 'table' => false, |
||
23 | 'foot_note' => true, |
||
24 | 'fenced_code_block' => true, |
||
25 | 'abbreviation' => true, |
||
26 | 'definition_list' => true, |
||
27 | 'inline_link' => true, // [link text](url "optional title") |
||
28 | 'reference_link' => true, // [link text] [id] |
||
29 | 'shortcut_link' => true, // [link text] |
||
30 | 'images' => true, |
||
31 | 'block_quote' => true, |
||
32 | 'code_block' => true, |
||
33 | 'html_block' => false, |
||
34 | 'auto_link' => true, |
||
35 | 'auto_mailto' => true, |
||
36 | 'entities' => true, |
||
37 | 'no_html' => true, |
||
38 | 'point_usernames' => true, // @user |
||
39 | 'point_posts' => true, // #post |
||
40 | 'point_tags' => false, // @todo implement |
||
41 | 'point_inline_images' => true, // https://i.skobk.in/i/facepalm.jpg |
||
42 | ); |
||
43 | |||
44 | 12 | public function __construct(array $features, RouterInterface $router) |
|
50 | |||
51 | /** |
||
52 | * Point.im breaks Markdown rule about quotation on next line |
||
53 | * |
||
54 | * @param $text |
||
55 | * |
||
56 | * @return mixed |
||
57 | */ |
||
58 | 1 | protected function doBlockQuotes($text) { |
|
73 | |||
74 | /** |
||
75 | * Point.im breaks Markdown double line wrap rule |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | 1 | protected function formParagraphs($text, $wrap_in_p = true) { |
|
106 | |||
107 | /** |
||
108 | * @param string $text |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 1 | public function doAutoLinks($text) |
|
120 | |||
121 | 1 | public function doAnchors($text) |
|
169 | |||
170 | protected function doAutoLinksInlineImageCallback($matches) |
||
178 | |||
179 | View Code Duplication | protected function doAnchorsPointUsernameCallback($matches) |
|
187 | |||
188 | View Code Duplication | protected function doAnchorsPointPostCallback($matches) |
|
196 | } |
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.