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 InsightUnspentOutputFinder extends UnspentOutputFinder { |
||
| 9 | |||
| 10 | protected $testnet; |
||
| 11 | |||
| 12 | protected $retryLimit; |
||
| 13 | protected $sleepTime; |
||
| 14 | |||
| 15 | /** |
||
| 16 | * @param bool $testnet |
||
| 17 | */ |
||
| 18 | public function __construct($testnet = false) { |
||
| 24 | |||
| 25 | View Code Duplication | public function getUTXOs(array $addresses) { |
|
| 42 | |||
| 43 | /** |
||
| 44 | * gets unspent outputs for a batch of addresses, returning and array of outputs with hash, index, value, and script pub hex |
||
| 45 | * |
||
| 46 | * @param string[] $addresses |
||
| 47 | * @return array 2d array of unspent outputs as ['hash' => $hash, 'index' => $index, 'value' => $value, 'address' => $address, 'script_hex' => $scriptHex] |
||
| 48 | * @throws \Exception |
||
| 49 | */ |
||
| 50 | protected function getUnspentOutputs($addresses) { |
||
| 98 | } |
||
| 99 |
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.