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

WalletV2Sweeper::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 20
Code Lines 11

Duplication

Lines 6
Ratio 30 %

Importance

Changes 0
Metric Value
dl 6
loc 20
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 8

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

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