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 declare(strict_types=1); |
||
21 | class Pool implements PoolUtilizerInterface |
||
22 | { |
||
23 | /** |
||
24 | * @var LoopInterface |
||
25 | */ |
||
26 | protected $loop; |
||
27 | |||
28 | /** |
||
29 | * @var PoolInfoInterface |
||
30 | */ |
||
31 | protected $pool; |
||
32 | |||
33 | /** |
||
34 | * @var Pool |
||
35 | */ |
||
36 | protected static $instance = null; |
||
37 | |||
38 | /** |
||
39 | * @var bool |
||
40 | */ |
||
41 | protected static $reset = false; |
||
42 | |||
43 | /** |
||
44 | * @param LoopInterface $loop |
||
45 | * @param array $config |
||
46 | */ |
||
47 | protected function __construct(LoopInterface $loop, array $config = []) |
||
59 | 4 | ||
60 | 4 | /** |
|
61 | 4 | * @param LoopInterface|null $loop |
|
62 | * @param array $config |
||
63 | * @throws \Exception |
||
64 | * @return Pool |
||
65 | */ |
||
66 | public static function getInstance(LoopInterface $loop = null, array $config = []) |
||
78 | |||
79 | public static function reset() |
||
83 | |||
84 | /** |
||
85 | * @param $className |
||
86 | 4 | * @param $tableName |
|
87 | * @param $function |
||
88 | 4 | * @param array $arguments |
|
89 | 4 | * @return PromiseInterface |
|
90 | */ |
||
91 | public function call($className, $tableName, $function, array $arguments) |
||
99 | 25 | ||
100 | public function paginate($tableName, $params, $settings) |
||
108 | |||
109 | private function paginateCall($tableName, $params, $settings) |
||
117 | |||
118 | View Code Duplication | protected function waitForPaginateCall($tableName, $params, $settings) |
|
134 | |||
135 | /** |
||
136 | * @inheritDoc |
||
137 | */ |
||
138 | public function info() |
||
146 | |||
147 | /** |
||
148 | * @return LoopInterface |
||
149 | */ |
||
150 | public function getLoop() |
||
154 | |||
155 | /** |
||
156 | * @return PoolInfoInterface |
||
157 | */ |
||
158 | public function getPool() |
||
162 | |||
163 | /** |
||
164 | * @param array $config |
||
165 | * @return array |
||
166 | */ |
||
167 | protected function applyConfig(array $config) |
||
179 | 1 | ||
180 | /** |
||
181 | * @param $className |
||
182 | * @param $tableName |
||
183 | * @param $function |
||
184 | * @param array $arguments |
||
185 | 1 | * @return PromiseInterface |
|
186 | */ |
||
187 | 1 | protected function poolCall($className, $tableName, $function, array $arguments) |
|
198 | |||
199 | /** |
||
200 | * @param $tableName |
||
201 | * @param $function |
||
202 | * @param array $arguments |
||
203 | * @return PromiseInterface |
||
204 | */ |
||
205 | View Code Duplication | protected function waitForPoolCall($tableName, $function, array $arguments) |
|
221 | } |
||
222 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.