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 |
||
16 | class OgSeoGenerator extends AbstractSeoGenerator |
||
17 | { |
||
18 | /** |
||
19 | * @param string $content |
||
20 | * |
||
21 | * @return $this |
||
22 | */ |
||
23 | public function setType($content) |
||
27 | |||
28 | /** |
||
29 | * @return MetaTag |
||
30 | */ |
||
31 | public function getType() |
||
35 | |||
36 | /** |
||
37 | * @param string $content |
||
38 | * |
||
39 | * @return $this |
||
40 | */ |
||
41 | public function setTitle($content) |
||
45 | |||
46 | /** |
||
47 | * @return MetaTag |
||
48 | */ |
||
49 | public function getTitle() |
||
53 | |||
54 | /** |
||
55 | * @param string $content |
||
56 | * |
||
57 | * @return $this |
||
58 | */ |
||
59 | public function setDescription($content) |
||
63 | |||
64 | /** |
||
65 | * @return MetaTag |
||
66 | */ |
||
67 | public function getDescription() |
||
71 | |||
72 | /** |
||
73 | * @param string $content |
||
74 | * |
||
75 | * @return $this |
||
76 | */ |
||
77 | public function setImage($content) |
||
86 | |||
87 | /** |
||
88 | * @return MetaTag |
||
89 | */ |
||
90 | public function getImage() |
||
94 | |||
95 | /** |
||
96 | * @param string $content |
||
97 | * |
||
98 | * @return $this |
||
99 | */ |
||
100 | public function setUrl($content) |
||
104 | |||
105 | /** |
||
106 | * @return MetaTag |
||
107 | */ |
||
108 | public function getUrl() |
||
112 | |||
113 | /** |
||
114 | * Generate seo tags from given resource. |
||
115 | * |
||
116 | * @param TitleSeoInterface|DescriptionSeoInterface|ImageSeoInterface $resource |
||
117 | * |
||
118 | * @return $this |
||
119 | */ |
||
120 | View Code Duplication | public function fromResource($resource) |
|
134 | |||
135 | /** |
||
136 | * @param string $type |
||
137 | * |
||
138 | * @return MetaTag |
||
139 | */ |
||
140 | public function get($type) |
||
144 | |||
145 | /** |
||
146 | * @param string $type |
||
147 | * @param string $value |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function set($type, $value) |
||
160 | } |
||
161 |
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.