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 |
||
18 | trait FontTrait |
||
19 | { |
||
20 | /** |
||
21 | * Get argument value |
||
22 | * |
||
23 | * @param string $name |
||
24 | * |
||
25 | * @return string |
||
26 | */ |
||
27 | abstract protected function getArgumentValue($name); |
||
28 | |||
29 | /** |
||
30 | * Set argument |
||
31 | * |
||
32 | * @param string $argument |
||
33 | * |
||
34 | * @return $this |
||
35 | */ |
||
36 | abstract protected function setArgument($argument); |
||
37 | |||
38 | /** |
||
39 | * Get PDF settings |
||
40 | * |
||
41 | * @return string |
||
42 | */ |
||
43 | abstract public function getPdfSettings(); |
||
44 | |||
45 | /** |
||
46 | * Get cannot embed font policy |
||
47 | * |
||
48 | * @return string |
||
49 | */ |
||
50 | View Code Duplication | public function getCannotEmbedFontPolicy() |
|
64 | |||
65 | /** |
||
66 | * Set cannot embed font policy |
||
67 | * |
||
68 | * @param string $cannotEmbedFontPolicy |
||
69 | * |
||
70 | * @param \InvalidArgumentException |
||
71 | * |
||
72 | * @return $this |
||
73 | */ |
||
74 | public function setCannotEmbedFontPolicy($cannotEmbedFontPolicy) |
||
85 | |||
86 | /** |
||
87 | * Whether to embed all fonts |
||
88 | * |
||
89 | * @return bool |
||
90 | */ |
||
91 | public function isEmbedAllFonts() |
||
105 | |||
106 | /** |
||
107 | * Set embed all fonts flag |
||
108 | * |
||
109 | * @param string $embedAllFonts |
||
110 | * |
||
111 | * @return $this |
||
112 | */ |
||
113 | public function setEmbedAllFonts($embedAllFonts) |
||
119 | |||
120 | /** |
||
121 | * Get max subset pct |
||
122 | * |
||
123 | * @return int |
||
124 | */ |
||
125 | public function getMaxSubsetPct() |
||
134 | |||
135 | /** |
||
136 | * Set max subset pct |
||
137 | * |
||
138 | * @param int $maxSubsetPct |
||
139 | * |
||
140 | * @return $this |
||
141 | */ |
||
142 | public function setMaxSubsetPct($maxSubsetPct) |
||
148 | |||
149 | /** |
||
150 | * Whether to subset fonts |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function isSubsetFonts() |
||
163 | |||
164 | /** |
||
165 | * Set subset fonts flag |
||
166 | * |
||
167 | * @param bool $subsetFonts |
||
168 | * |
||
169 | * @return $this |
||
170 | */ |
||
171 | public function setSubsetFonts($subsetFonts) |
||
177 | } |
||
178 |
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.