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 |
||
14 | class DriverStandard extends DriverAbstract implements DriverInterface |
||
15 | { |
||
16 | /** |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $options; |
||
20 | |||
21 | /** |
||
22 | * @var InvokerInterface |
||
23 | */ |
||
24 | protected $invoker; |
||
25 | |||
26 | /** |
||
27 | * @var FlagResolverInterface |
||
28 | */ |
||
29 | protected $flagPermission; |
||
30 | |||
31 | /** |
||
32 | * @param LoopInterface $loop |
||
33 | * @param array $options |
||
34 | */ |
||
35 | public function __construct(LoopInterface $loop, $options = []) |
||
42 | |||
43 | /** |
||
44 | * @override |
||
45 | * @inheritDoc |
||
46 | */ |
||
47 | public function access($path, $mode = 0755) |
||
51 | |||
52 | /** |
||
53 | * @override |
||
54 | * @inheritDoc |
||
55 | */ |
||
56 | public function append($path, $data = '') |
||
60 | |||
61 | /** |
||
62 | * @override |
||
63 | * @inheritDoc |
||
64 | */ |
||
65 | public function chmod($path, $mode) |
||
69 | |||
70 | /** |
||
71 | * @override |
||
72 | * @inheritDoc |
||
73 | */ |
||
74 | public function chown($path, $uid = -1, $gid = -1) |
||
78 | |||
79 | /** |
||
80 | * @override |
||
81 | * @inheritDoc |
||
82 | */ |
||
83 | public function exists($path) |
||
91 | |||
92 | /** |
||
93 | * @override |
||
94 | * @inheritDoc |
||
95 | */ |
||
96 | public function link($srcPath, $dstPath) |
||
100 | |||
101 | /** |
||
102 | * @override |
||
103 | * @inheritDoc |
||
104 | */ |
||
105 | public function ls($path) |
||
109 | |||
110 | /** |
||
111 | * @override |
||
112 | * @inheritDoc |
||
113 | */ |
||
114 | public function mkdir($path, $mode = 0755) |
||
118 | |||
119 | /** |
||
120 | * @override |
||
121 | * @inheritDoc |
||
122 | */ |
||
123 | public function prepend($path, $data = '') |
||
127 | |||
128 | /** |
||
129 | * @override |
||
130 | * @inheritDoc |
||
131 | */ |
||
132 | public function readlink($path) |
||
136 | |||
137 | /** |
||
138 | * @override |
||
139 | * @inheritDoc |
||
140 | */ |
||
141 | public function realpath($path) |
||
145 | |||
146 | /** |
||
147 | * @override |
||
148 | * @inheritDoc |
||
149 | */ |
||
150 | public function rename($srcPath, $dstPath) |
||
154 | |||
155 | /** |
||
156 | * @override |
||
157 | * @inheritDoc |
||
158 | */ |
||
159 | public function rmdir($path) |
||
163 | |||
164 | /** |
||
165 | * @override |
||
166 | * @inheritDoc |
||
167 | */ |
||
168 | public function stat($path) |
||
187 | |||
188 | /** |
||
189 | * @override |
||
190 | * @inheritDoc |
||
191 | */ |
||
192 | public function symlink($srcPath, $dstPath) |
||
196 | |||
197 | /** |
||
198 | * @override |
||
199 | * @inheritDoc |
||
200 | */ |
||
201 | public function truncate($path, $len = 0) |
||
205 | |||
206 | /** |
||
207 | * @override |
||
208 | * @inheritDoc |
||
209 | */ |
||
210 | public function unlink($path) |
||
214 | |||
215 | /** |
||
216 | * @internal |
||
217 | * @override |
||
218 | * @inheritDoc |
||
219 | */ |
||
220 | public function call($func, $args = []) |
||
235 | |||
236 | /** |
||
237 | * Get path. |
||
238 | * |
||
239 | * @param string $path |
||
240 | * @return string |
||
241 | */ |
||
242 | protected function getPath($path) |
||
246 | |||
247 | /** |
||
248 | * Create valid configuration for the driver. |
||
249 | * |
||
250 | * @param array $options |
||
251 | * @return array |
||
252 | */ |
||
253 | protected function createConfiguration($options = []) |
||
260 | |||
261 | /** |
||
262 | * Create invoker for the driver. |
||
263 | * |
||
264 | * @return InvokerInterface |
||
265 | */ |
||
266 | View Code Duplication | protected function createInvoker() |
|
274 | } |
||
275 |
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.