| Conditions | 15 |
| Paths | 144 |
| Total Lines | 49 |
| Code Lines | 26 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 46 | public function unlock($options, callable $fn = null) { |
||
| 47 | // explode the wallet data |
||
| 48 | $password = isset($options['passphrase']) ? $options['passphrase'] : (isset($options['password']) ? $options['password'] : null); |
||
| 49 | $primaryMnemonic = $this->primaryMnemonic; |
||
| 50 | $primaryPrivateKey = isset($options['primary_private_key']) ? $options['primary_private_key'] : null; |
||
| 51 | |||
| 52 | if ($primaryMnemonic && $primaryPrivateKey) { |
||
| 53 | throw new \InvalidArgumentException("Can't specify Primary Mnemonic and Primary PrivateKey"); |
||
| 54 | } |
||
| 55 | |||
| 56 | if (!$primaryMnemonic && !$primaryPrivateKey) { |
||
| 57 | throw new \InvalidArgumentException("Can't init wallet with Primary Mnemonic or Primary PrivateKey"); |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($primaryMnemonic && !$password) { |
||
| 61 | throw new \InvalidArgumentException("Can't init wallet with Primary Mnemonic without a passphrase"); |
||
| 62 | } |
||
| 63 | |||
| 64 | if ($primaryPrivateKey) { |
||
| 65 | if (!($primaryPrivateKey instanceof HierarchicalKey)) { |
||
| 66 | $primaryPrivateKey = HierarchicalKeyFactory::fromExtended($primaryPrivateKey); |
||
| 67 | } |
||
| 68 | } else { |
||
| 69 | // convert the mnemonic to a seed using BIP39 standard |
||
| 70 | $primarySeed = (new Bip39SeedGenerator())->getSeed($primaryMnemonic, $password); |
||
| 71 | // create BIP32 private key from the seed |
||
| 72 | $primaryPrivateKey = HierarchicalKeyFactory::fromEntropy($primarySeed); |
||
| 73 | } |
||
| 74 | |||
| 75 | $this->primaryPrivateKey = BIP32Key::create($primaryPrivateKey, "m"); |
||
| 76 | |||
| 77 | // create checksum (address) of the primary privatekey to compare to the stored checksum |
||
| 78 | $checksum = $this->primaryPrivateKey->key()->getPublicKey()->getAddress()->getAddress(); |
||
| 79 | if ($checksum != $this->checksum) { |
||
| 80 | throw new \Exception("Checksum [{$checksum}] does not match [{$this->checksum}], most likely due to incorrect password"); |
||
| 81 | } |
||
| 82 | |||
| 83 | $this->locked = false; |
||
| 84 | |||
| 85 | // if the response suggests we should upgrade to a different blocktrail cosigning key then we should |
||
| 86 | if (isset($data['upgrade_key_index'])) { |
||
|
|
|||
| 87 | $this->upgradeKeyIndex($data['upgrade_key_index']); |
||
| 88 | } |
||
| 89 | |||
| 90 | if ($fn) { |
||
| 91 | $fn($this); |
||
| 92 | $this->lock(); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 117 |
This check looks for calls to
isset(...)orempty()on variables that are yet undefined. These calls will always produce the same result and can be removed.This is most likely caused by the renaming of a variable or the removal of a function/method parameter.