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 |
||
| 15 | class LaunchPlugin implements PluginInterface |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * @throws \Yansongda\Pay\Exception\ContainerDependencyException |
||
| 19 | * @throws \Yansongda\Pay\Exception\ContainerException |
||
| 20 | * @throws \Yansongda\Pay\Exception\InvalidConfigException |
||
| 21 | * @throws \Yansongda\Pay\Exception\InvalidResponseException |
||
| 22 | * @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
||
| 23 | */ |
||
| 24 | public function assembly(Rocket $rocket, Closure $next): Rocket |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @throws \Yansongda\Pay\Exception\ContainerDependencyException |
||
| 40 | * @throws \Yansongda\Pay\Exception\ContainerException |
||
| 41 | * @throws \Yansongda\Pay\Exception\InvalidConfigException |
||
| 42 | * @throws \Yansongda\Pay\Exception\InvalidResponseException |
||
| 43 | * @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
||
| 44 | */ |
||
| 45 | protected function getMethodResponse(Rocket $rocket): Collection |
||
| 59 | |||
| 60 | /** |
||
| 61 | * @throws \Yansongda\Pay\Exception\ContainerDependencyException |
||
| 62 | * @throws \Yansongda\Pay\Exception\ContainerException |
||
| 63 | * @throws \Yansongda\Pay\Exception\InvalidConfigException |
||
| 64 | * @throws \Yansongda\Pay\Exception\InvalidResponseException |
||
| 65 | * @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
||
| 66 | */ |
||
| 67 | protected function verifySign(Rocket $rocket): void |
||
| 82 | |||
| 83 | protected function getResponseKey(Rocket $rocket): string |
||
| 89 | |||
| 90 | /** |
||
| 91 | * @throws \Yansongda\Pay\Exception\ContainerDependencyException |
||
| 92 | * @throws \Yansongda\Pay\Exception\ContainerException |
||
| 93 | * @throws \Yansongda\Pay\Exception\ServiceNotFoundException |
||
| 94 | * @throws \Yansongda\Pay\Exception\InvalidConfigException |
||
| 95 | */ |
||
| 96 | View Code Duplication | protected function getAlipayPublicKey(Rocket $rocket) |
|
| 106 | } |
||
| 107 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: