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 |
||
19 | class Icon |
||
20 | { |
||
21 | /** |
||
22 | * @var array |
||
23 | */ |
||
24 | private $options = []; |
||
25 | |||
26 | /** |
||
27 | * @param string $cssPrefix |
||
28 | * @param string $name |
||
29 | * @param array $options |
||
30 | */ |
||
31 | public function __construct($cssPrefix, $name, $options = []) |
||
41 | |||
42 | /** |
||
43 | * @return string |
||
44 | */ |
||
45 | public function __toString() |
||
53 | |||
54 | /** |
||
55 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
56 | * @throws \yii\base\InvalidConfigException |
||
57 | */ |
||
58 | public function inverse() |
||
62 | |||
63 | /** |
||
64 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
65 | * @throws \yii\base\InvalidConfigException |
||
66 | */ |
||
67 | public function spin() |
||
71 | |||
72 | /** |
||
73 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
74 | * @throws \yii\base\InvalidConfigException |
||
75 | */ |
||
76 | public function pulse() |
||
80 | |||
81 | /** |
||
82 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
83 | * @throws \yii\base\InvalidConfigException |
||
84 | */ |
||
85 | public function fixedWidth() |
||
89 | |||
90 | /** |
||
91 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
92 | * @throws \yii\base\InvalidConfigException |
||
93 | */ |
||
94 | public function li() |
||
98 | |||
99 | /** |
||
100 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
101 | * @throws \yii\base\InvalidConfigException |
||
102 | */ |
||
103 | public function border() |
||
107 | |||
108 | /** |
||
109 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
110 | * @throws \yii\base\InvalidConfigException |
||
111 | */ |
||
112 | public function pullLeft() |
||
116 | |||
117 | /** |
||
118 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
119 | * @throws \yii\base\InvalidConfigException |
||
120 | */ |
||
121 | public function pullRight() |
||
125 | |||
126 | /** |
||
127 | * @param string $value |
||
128 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
129 | * @throws \yii\base\InvalidConfigException |
||
130 | */ |
||
131 | public function size($value) |
||
158 | |||
159 | /** |
||
160 | * @param string $value |
||
161 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
162 | * @throws \yii\base\InvalidConfigException |
||
163 | */ |
||
164 | View Code Duplication | public function rotate($value) |
|
178 | |||
179 | /** |
||
180 | * @param string $value |
||
181 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
182 | * @throws \yii\base\InvalidConfigException |
||
183 | */ |
||
184 | View Code Duplication | public function flip($value) |
|
198 | |||
199 | /** |
||
200 | * @param string $class |
||
201 | * @param bool $condition |
||
202 | * @param string|bool $throw |
||
203 | * @return \rmrevin\yii\fontawesome\component\Icon |
||
204 | * @throws \yii\base\InvalidConfigException |
||
205 | * @codeCoverageIgnore |
||
206 | */ |
||
207 | public function addCssClass($class, $condition = true, $throw = false) |
||
223 | } |
||
224 |
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.