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 |
||
29 | View Code Duplication | class CashCoupon |
|
30 | { |
||
31 | /** |
||
32 | * @var API |
||
33 | */ |
||
34 | protected $api; |
||
35 | |||
36 | /** |
||
37 | * Merchant instance. |
||
38 | * |
||
39 | * @var \EasyWeChat\Payment\Merchant |
||
40 | */ |
||
41 | protected $merchant; |
||
42 | |||
43 | /** |
||
44 | * Constructor. |
||
45 | * |
||
46 | * @param Merchant $merchant |
||
47 | */ |
||
48 | public function __construct(Merchant $merchant) |
||
52 | |||
53 | /** |
||
54 | * Merchant setter. |
||
55 | * |
||
56 | * @param Merchant $merchant |
||
57 | */ |
||
58 | public function setMerchant(Merchant $merchant) |
||
62 | |||
63 | /** |
||
64 | * Merchant getter. |
||
65 | * |
||
66 | * @return Merchant |
||
67 | */ |
||
68 | public function getMerchant() |
||
72 | |||
73 | /** |
||
74 | * API setter. |
||
75 | * |
||
76 | * @param API $api |
||
77 | */ |
||
78 | public function setAPI(API $api) |
||
82 | |||
83 | /** |
||
84 | * Return API instance. |
||
85 | * |
||
86 | * @return API |
||
87 | */ |
||
88 | public function getAPI() |
||
92 | |||
93 | /** |
||
94 | * Magic call. |
||
95 | * |
||
96 | * @param string $method |
||
97 | * @param array $args |
||
98 | * |
||
99 | * @return mixed |
||
100 | * |
||
101 | * @codeCoverageIgnore |
||
102 | */ |
||
103 | public function __call($method, $args) |
||
109 | } |
||
110 |