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 |
||
13 | class DriverEio extends DriverAbstract implements DriverInterface |
||
14 | { |
||
15 | /** |
||
16 | * @var InvokerInterface |
||
17 | */ |
||
18 | protected $invoker; |
||
19 | |||
20 | /** |
||
21 | * @var resource |
||
22 | */ |
||
23 | protected $stream; |
||
24 | |||
25 | /** |
||
26 | * @var bool |
||
27 | */ |
||
28 | protected $active = false; |
||
29 | |||
30 | /** |
||
31 | * @param LoopInterface $loop |
||
32 | * @param array $options |
||
33 | */ |
||
34 | public function __construct(LoopInterface $loop, $options = []) |
||
42 | |||
43 | /** |
||
44 | * @override |
||
45 | * @inheritDoc |
||
46 | */ |
||
47 | public function stat($path) |
||
53 | |||
54 | /** |
||
55 | * @override |
||
56 | * @inheritDoc |
||
57 | */ |
||
58 | public function chmod($path, $mode) |
||
64 | |||
65 | /** |
||
66 | * @override |
||
67 | * @inheritDoc |
||
68 | */ |
||
69 | public function chown($path, $uid = -1, $gid = -1) |
||
75 | |||
76 | /** |
||
77 | * @internal |
||
78 | * @override |
||
79 | * @inheritDoc |
||
80 | */ |
||
81 | public function call($func, $args = []) |
||
104 | |||
105 | /** |
||
106 | * @param string $func |
||
107 | * @param array $args |
||
108 | * @return PromiseInterface |
||
|
|||
109 | */ |
||
110 | protected function callDelayed($func, $args = []) |
||
139 | |||
140 | protected function register() |
||
149 | |||
150 | protected function unregister() |
||
159 | |||
160 | public function handleEvent() |
||
177 | |||
178 | public function workPendingCount() |
||
182 | |||
183 | /** |
||
184 | * Get path. |
||
185 | * |
||
186 | * @param string $path |
||
187 | * @return string |
||
188 | */ |
||
189 | protected function getPath($path) |
||
193 | |||
194 | /** |
||
195 | * Create valid configuration for the driver. |
||
196 | * |
||
197 | * @param array $options |
||
198 | * @return array |
||
199 | */ |
||
200 | View Code Duplication | protected function createConfiguration($options = []) |
|
208 | |||
209 | /** |
||
210 | * Create invoker for the driver. |
||
211 | * |
||
212 | * @return InvokerInterface |
||
213 | */ |
||
214 | View Code Duplication | protected function createInvoker() |
|
222 | } |
||
223 |
This check compares the return type specified in the
@return
annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.