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 |
||
12 | class HAtomAdapter extends AbstractAdapter |
||
13 | { |
||
14 | View Code Duplication | public function extractTitle(Crawler $crawler) |
|
28 | |||
29 | public function extractImage(Crawler $crawler) |
||
34 | |||
35 | View Code Duplication | public function extractDescription(Crawler $crawler) |
|
48 | |||
49 | View Code Duplication | public function extractKeywords(Crawler $crawler) |
|
62 | |||
63 | View Code Duplication | public function extractBody(Crawler $crawler) |
|
64 | { |
||
65 | $ret = null; |
||
66 | $crawler->filter(".hentry .entry-content") |
||
67 | ->each( |
||
68 | function(Crawler $node) use (&$ret) { |
||
69 | $ret = $this->normalizeHtml($node->html()); |
||
70 | } |
||
71 | ); |
||
72 | |||
73 | return $ret; |
||
74 | } |
||
75 | |||
76 | View Code Duplication | public function extractPublishDate(Crawler $crawler) |
|
92 | |||
93 | View Code Duplication | public function extractAuthor(Crawler $crawler) |
|
105 | } |
||
106 |
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.