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 |
||
17 | class BasicSeoGenerator extends AbstractSeoGenerator |
||
18 | { |
||
19 | /** |
||
20 | * @param string $content |
||
21 | * |
||
22 | * @return $this |
||
23 | */ |
||
24 | public function setTitle($content) |
||
30 | |||
31 | /** |
||
32 | * @return TitleTag |
||
33 | */ |
||
34 | public function getTitle() |
||
38 | |||
39 | /** |
||
40 | * @param string $content |
||
41 | * |
||
42 | * @return $this |
||
43 | */ |
||
44 | public function setDescription($content) |
||
53 | |||
54 | /** |
||
55 | * @return MetaTag |
||
56 | */ |
||
57 | public function getDescription() |
||
61 | |||
62 | /** |
||
63 | * @param string $keywords |
||
64 | * |
||
65 | * @return $this |
||
66 | */ |
||
67 | public function setKeywords($keywords) |
||
76 | |||
77 | /** |
||
78 | * @return MetaTag |
||
79 | */ |
||
80 | public function getKeywords() |
||
84 | |||
85 | /** |
||
86 | * @param bool $shouldIndex |
||
87 | * @param bool $shouldFollow |
||
88 | * |
||
89 | * @return $this |
||
90 | */ |
||
91 | public function setRobots($shouldIndex, $shouldFollow) |
||
103 | |||
104 | /** |
||
105 | * @param string $url |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | public function setCanonical($url) |
||
117 | |||
118 | /** |
||
119 | * Generate seo tags from given resource. |
||
120 | * |
||
121 | * @param TitleSeoInterface|DescriptionSeoInterface|KeywordsSeoInterface $resource |
||
122 | * |
||
123 | * @return $this |
||
124 | */ |
||
125 | View Code Duplication | public function fromResource($resource) |
|
139 | } |
||
140 |
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.