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 |
||
12 | class DriverStandard extends DriverAbstract implements DriverInterface |
||
13 | { |
||
14 | /** |
||
15 | * @var InvokerInterface |
||
16 | */ |
||
17 | protected $invoker; |
||
18 | |||
19 | /** |
||
20 | * @param LoopInterface $loop |
||
21 | * @param array $options |
||
22 | */ |
||
23 | public function __construct(LoopInterface $loop, $options = []) |
||
29 | |||
30 | /** |
||
31 | * @override |
||
32 | * @inheritDoc |
||
33 | */ |
||
34 | public function stat($path) |
||
45 | |||
46 | /** |
||
47 | * @override |
||
48 | * @inheritDoc |
||
49 | */ |
||
50 | public function chmod($path, $mode) |
||
56 | |||
57 | /** |
||
58 | * @override |
||
59 | * @inheritDoc |
||
60 | */ |
||
61 | public function chown($path, $uid = -1, $gid = -1) |
||
67 | |||
68 | /** |
||
69 | * @internal |
||
70 | * @override |
||
71 | * @inheritDoc |
||
72 | */ |
||
73 | public function call($func, $args = []) |
||
88 | |||
89 | /** |
||
90 | * Get path. |
||
91 | * |
||
92 | * @param string $path |
||
93 | * @return string |
||
94 | */ |
||
95 | protected function getPath($path) |
||
99 | |||
100 | /** |
||
101 | * Create valid configuration for the driver. |
||
102 | * |
||
103 | * @param array $options |
||
104 | * @return array |
||
105 | */ |
||
106 | View Code Duplication | protected function createConfiguration($options = []) |
|
114 | |||
115 | /** |
||
116 | * Create invoker for the driver. |
||
117 | * |
||
118 | * @return InvokerInterface |
||
119 | */ |
||
120 | View Code Duplication | protected function createInvoker() |
|
128 | } |
||
129 |
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.