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 |
||
10 | |||
11 | class PayPlugin implements PluginInterface |
||
12 | { |
||
13 | public function assembly(Rocket $rocket, Closure $next): Rocket |
||
14 | { |
||
15 | $rocket->mergePayload([ |
||
16 | 'method' => 'alipay.trade.pay', |
||
17 | 'biz_content' => array_merge( |
||
18 | [ |
||
19 | 'product_code' => 'FACE_TO_FACE_PAYMENT', |
||
20 | 'scene' => 'bar_code', |
||
21 | ], |
||
22 | $rocket->getParams(), |
||
23 | ), |
||
|
|||
24 | ]); |
||
25 | |||
26 | return $next($rocket); |
||
27 | } |
||
28 | } |
||
29 |