| Conditions | 7 |
| Paths | 8 |
| Total Lines | 70 |
| Code Lines | 40 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 5 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 50 | public function viewWallet(Response $response): Response |
||
| 51 | { |
||
| 52 | $settings = $this->app->get('settings'); |
||
| 53 | $accountFile = $this->app->get('accountfile'); |
||
| 54 | $bcFile = $this->app->get('datadir') . 'bcVars.json'; |
||
| 55 | $heFile = $this->app->get('datadir') . 'heTokens.json'; |
||
| 56 | |||
| 57 | $cache_interval = $settings['delay']; |
||
| 58 | $current_time = time(); |
||
| 59 | |||
| 60 | /* |
||
| 61 | * Get Hive engine tokens from account |
||
| 62 | */ |
||
| 63 | if ((!file_exists($heFile)) || ($current_time - filemtime($heFile) > $cache_interval)) { |
||
| 64 | $config = [ |
||
| 65 | 'debug' => false, |
||
| 66 | 'heNode' => 'api.hive-engine.com/rpc', |
||
| 67 | 'hiveNode' => 'anyx.io', |
||
| 68 | ]; |
||
| 69 | |||
| 70 | $heApi = new HeAccount($config); |
||
| 71 | |||
| 72 | $heResponse = $heApi->getAccountBalance($settings['author']); |
||
| 73 | $heResult = json_encode($heResponse, JSON_PRETTY_PRINT); |
||
| 74 | file_put_contents($heFile, $heResult); |
||
| 75 | } |
||
| 76 | |||
| 77 | $heTokens = json_decode(file_get_contents($heFile), true); |
||
| 78 | |||
| 79 | /* |
||
| 80 | * Get HIVE/ HBD & Savings from account |
||
| 81 | */ |
||
| 82 | $apiConfig = [ |
||
| 83 | 'webservice_url' => $settings['api'], |
||
| 84 | 'debug' => false, |
||
| 85 | ]; |
||
| 86 | $api = new HiveCondenser($apiConfig); |
||
| 87 | |||
| 88 | if ((!file_exists($accountFile)) || ($current_time - filemtime($accountFile) > $cache_interval)) { |
||
| 89 | $result = json_encode($api->getAccounts($settings['author']), JSON_PRETTY_PRINT); |
||
| 90 | file_put_contents($accountFile, $result); |
||
| 91 | } |
||
| 92 | |||
| 93 | if ((!file_exists($bcFile)) || ($current_time - filemtime($bcFile) > ($cache_interval * 2))) { |
||
| 94 | $result = json_encode($api->getDynamicGlobalProperties(), JSON_PRETTY_PRINT); |
||
| 95 | file_put_contents($bcFile, $result); |
||
| 96 | } |
||
| 97 | |||
| 98 | $account = json_decode(file_get_contents($accountFile), true); |
||
| 99 | |||
| 100 | /* |
||
| 101 | * Convert VESTS to HP |
||
| 102 | */ |
||
| 103 | $bcVars = json_decode(file_get_contents($bcFile), true); |
||
| 104 | $vests = []; |
||
| 105 | $vests['tvfh'] = (float)$bcVars['total_vesting_fund_hive']; |
||
| 106 | $vests['tvs'] = (float)$bcVars['total_vesting_shares']; |
||
| 107 | $vests['totalVests'] = $vests['tvfh'] / $vests['tvs']; |
||
| 108 | $vests['userHP'] = round((float)$account[0]['vesting_shares'] * $vests['totalVests'], 3); |
||
| 109 | $vests['delegHP'] = round((float)$account[0]['delegated_vesting_shares'] * $vests['totalVests'], 3); |
||
| 110 | |||
| 111 | /* |
||
| 112 | * Just render the view with vars |
||
| 113 | */ |
||
| 114 | return $this->app->get('view')->render($response, '/admin/admin-wallet.html', [ |
||
| 115 | 'settings' => $settings, |
||
| 116 | 'vests' => $vests, |
||
| 117 | 'blockchain' => $bcVars, |
||
| 118 | 'hetokens' => $heTokens, |
||
| 119 | 'account' => $account[0], |
||
| 120 | ]); |
||
| 123 |