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 |
||
7 | class BtcE extends ExchangeAbstract |
||
8 | { |
||
9 | private $nonce = false; |
||
10 | |||
11 | |||
12 | /** |
||
13 | * @param $uri |
||
14 | * @param array $params |
||
15 | * @return mixed |
||
16 | * @throws \Exception |
||
17 | */ |
||
18 | 7 | public function send($uri, array $params = []) |
|
71 | |||
72 | /** |
||
73 | * |
||
74 | */ |
||
75 | 9 | public function setClient() |
|
79 | |||
80 | /** |
||
81 | * @param $btc |
||
82 | * @param $price |
||
83 | * @return mixed |
||
84 | * @throws \Exception |
||
85 | */ |
||
86 | 1 | View Code Duplication | public function buyOrder($btc, $price) |
95 | |||
96 | /** |
||
97 | * @param $btc |
||
98 | * @param $price |
||
99 | * @return mixed |
||
100 | * @throws \Exception |
||
101 | 1 | */ |
|
102 | View Code Duplication | public function sellOrder($btc, $price) |
|
111 | |||
112 | /** |
||
113 | * @return mixed |
||
114 | * @throws \Exception |
||
115 | 1 | */ |
|
116 | public function getInfo() |
||
120 | |||
121 | /** |
||
122 | * @return mixed |
||
123 | 1 | */ |
|
124 | public function getTicker() |
||
128 | |||
129 | |||
130 | 1 | /** |
|
131 | * @return array |
||
132 | 1 | */ |
|
133 | 1 | public function getOrderBook($pair = 'btc_usd') |
|
137 | |||
138 | 1 | ||
139 | /** |
||
140 | 1 | * @return mixed |
|
141 | * @throws \Exception |
||
142 | */ |
||
143 | 1 | public function getOrders() |
|
149 | |||
150 | 1 | /** |
|
151 | * @return mixed |
||
152 | 1 | * @throws \Exception |
|
153 | 1 | */ |
|
154 | public function getTransactionHistory() |
||
158 | |||
159 | /** |
||
160 | * @return mixed |
||
161 | * @throws \Exception |
||
162 | */ |
||
163 | public function getTradeHistory() |
||
167 | |||
168 | |||
169 | /** |
||
170 | * @param $order_id |
||
171 | * @return mixed |
||
172 | * @throws \Exception |
||
173 | */ |
||
174 | public function cancelOrder($order_id) |
||
180 | |||
181 | |||
182 | } |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.