| Conditions | 14 |
| Paths | 92 |
| Total Lines | 54 |
| Code Lines | 32 |
| 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 |
||
| 71 | public function unlock($options, callable $fn = null) { |
||
| 72 | // explode the wallet data |
||
| 73 | $password = isset($options['passphrase']) ? $options['passphrase'] : (isset($options['password']) ? $options['password'] : null); |
||
| 74 | |||
| 75 | $encryptedPrimarySeed = $this->encryptedPrimarySeed; |
||
| 76 | $encryptedSecret = $this->encryptedSecret; |
||
| 77 | |||
| 78 | if (isset($options['primary_seed'])) { |
||
| 79 | if (!$options['primary_seed'] instanceof BufferInterface) { |
||
| 80 | throw new \RuntimeException('Primary Seed must be a BufferInterface'); |
||
| 81 | } |
||
| 82 | $this->primarySeed = $options['primary_seed']; |
||
| 83 | } else { |
||
| 84 | if (!$password) { |
||
| 85 | throw new \InvalidArgumentException("Can't init wallet with Primary Seed without a passphrase"); |
||
| 86 | } elseif (!$encryptedSecret) { |
||
| 87 | throw new \InvalidArgumentException("Can't init wallet with Primary Seed without a encrypted secret"); |
||
| 88 | } elseif (!$encryptedPrimarySeed) { |
||
| 89 | throw new \InvalidArgumentException("Can't init wallet without an Encrypted Primary Seed"); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (!$password instanceof Buffer) { |
||
| 93 | $password = new Buffer($password); |
||
| 94 | } |
||
| 95 | if (!($this->secret = Encryption::decrypt($encryptedSecret, $password))) { |
||
| 96 | throw new WalletDecryptException("Failed to decrypt secret with password"); |
||
| 97 | } |
||
| 98 | |||
| 99 | if (!($this->primarySeed = Encryption::decrypt($encryptedPrimarySeed, $this->secret))) { |
||
| 100 | throw new WalletDecryptException("Failed to decrypt primary seed with secret"); |
||
| 101 | } |
||
| 102 | } |
||
| 103 | $this->primaryPrivateKey = BIP32Key::create(HierarchicalKeyFactory::fromEntropy($this->primarySeed), "m"); |
||
| 104 | |||
| 105 | // create checksum (address) of the primary privatekey to compare to the stored checksum |
||
| 106 | $checksum = $this->primaryPrivateKey->publicKey()->getAddress()->getAddress(); |
||
| 107 | if ($checksum != $this->checksum) { |
||
| 108 | throw new \Exception("Checksum [{$checksum}] does not match [{$this->checksum}], most likely due to incorrect password"); |
||
| 109 | } |
||
| 110 | |||
| 111 | $this->locked = false; |
||
| 112 | |||
| 113 | // if the response suggests we should upgrade to a different blocktrail cosigning key then we should |
||
| 114 | if (isset($data['upgrade_key_index'])) { |
||
|
|
|||
| 115 | $this->upgradeKeyIndex($data['upgrade_key_index']); |
||
| 116 | } |
||
| 117 | |||
| 118 | if ($fn) { |
||
| 119 | $fn($this); |
||
| 120 | $this->lock(); |
||
| 121 | } |
||
| 122 | |||
| 123 | return true; |
||
| 124 | } |
||
| 125 | |||
| 165 |
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.