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 |
||
| 8 | class BlocktrailBatchUnspentOutputFinder extends UnspentOutputFinder { |
||
| 9 | |||
| 10 | protected $client; |
||
| 11 | protected $retryLimit; |
||
| 12 | protected $sleepTime; |
||
| 13 | protected $paginationLimit = 200; //max results to retrieve at a time |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param $apiKey |
||
| 17 | * @param $apiSecret |
||
| 18 | * @param string $network |
||
| 19 | * @param bool $testnet |
||
| 20 | * @param string $apiVersion |
||
| 21 | * @param null $apiEndpoint |
||
| 22 | */ |
||
| 23 | public function __construct($apiKey, $apiSecret, $network = 'BTC', $testnet = false, $apiVersion = 'v1', $apiEndpoint = null) { |
||
| 29 | |||
| 30 | /** |
||
| 31 | * modify the default limit on how many utxo results are returned per page |
||
| 32 | * @param $limit |
||
| 33 | */ |
||
| 34 | public function setPaginationLimit($limit) { |
||
| 37 | |||
| 38 | View Code Duplication | public function getUTXOs(array $addresses) { |
|
| 55 | |||
| 56 | /** |
||
| 57 | * gets unspent outputs for a batch of addresses, returning and array of outputs with hash, index, value, and script pub hex |
||
| 58 | * |
||
| 59 | * @param string[] $addresses |
||
| 60 | * @return array 2d array of unspent outputs as ['hash' => $hash, 'index' => $index, 'value' => $value, 'address' => $address, 'script_hex' => $scriptHex] |
||
| 61 | * @throws \Exception |
||
| 62 | */ |
||
| 63 | protected function getUnspentOutputs($addresses) { |
||
| 105 | } |
||
| 106 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.