Completed
Branch master (56c2f5)
by
unknown
07:05
created

WalletV2Sweeper   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 17.65 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 7
dl 6
loc 34
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 6 20 3

How to fix   Duplicated Code   

Duplicated Code

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
2
3
namespace Blocktrail\SDK;
4
5
6
use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
7
8
9
use BitWasp\Buffertools\Buffer;
10
use Blocktrail\CryptoJSAES\CryptoJSAES;
11
12
13
use Blocktrail\SDK\Exceptions\BlocktrailSDKException;
14
15
class WalletV2Sweeper extends WalletSweeper {
16
17
    /**
18
     * @param string              $encryptedPrimarySeed
19
     * @param string              $passwordEncryptedSecret
20
     * @param string              $backupSeed
21
     * @param string              $passphrase
22
     * @param array               $blocktrailPublicKeys
23
     * @param UnspentOutputFinder $utxoFinder
24
     * @param string              $network
25
     * @param bool                $testnet
26
     * @throws BlocktrailSDKException
27
     */
28
    public function __construct($encryptedPrimarySeed, $passwordEncryptedSecret, $backupSeed, $passphrase, array $blocktrailPublicKeys, UnspentOutputFinder $utxoFinder, $network = 'btc', $testnet = false) {
29
        // cleanup copy paste errors from mnemonics
30
        $encryptedPrimarySeed = str_replace("  ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($encryptedPrimarySeed))));
31
        $passwordEncryptedSecret = str_replace("  ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($passwordEncryptedSecret))));
32
        $backupSeed = str_replace("  ", " ", str_replace("\r\n", " ", str_replace("\n", " ", trim($backupSeed))));
33
34
        $bip39 = MnemonicFactory::bip39();
35
36 View Code Duplication
        if (!($secret = CryptoJSAES::decrypt(base64_encode($bip39->mnemonicToEntropy($passwordEncryptedSecret)->getBinary()), $passphrase))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
37
            throw new BlocktrailSDKException("Failed to decret password encrypted secret");
38
        }
39
40 View Code Duplication
        if (!($primarySeed = CryptoJSAES::decrypt(base64_encode($bip39->mnemonicToEntropy($encryptedPrimarySeed)->getBinary()), $secret))) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

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.

Loading history...
41
            throw new BlocktrailSDKException("failed to decrypt encrypted primary seed! (weird!)");
42
        }
43
44
        $backupSeed = $bip39->mnemonicToEntropy($backupSeed);
45
46
        parent::__construct(new Buffer($primarySeed), $backupSeed, $blocktrailPublicKeys, $utxoFinder, $network, $testnet);
47
    }
48
}
49