| Conditions | 7 |
| Paths | 75 |
| Total Lines | 75 |
| Code Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 1 | Features | 2 |
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 |
||
| 40 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 41 | { |
||
| 42 | $config = $this->getApplication()->getConfig(); |
||
| 43 | $logger = $this->getApplication()->getLogger(); |
||
| 44 | $client = $this->getApplication()->getClient(); |
||
| 45 | |||
| 46 | try { |
||
| 47 | $influxDbClient = $this->getApplication()->getInfluxDbClient( |
||
| 48 | $config->get('influxdb-host'), |
||
| 49 | $config->get('influxdb-port'), |
||
| 50 | $config->get('influxdb-user'), |
||
| 51 | $config->get('influxdb-password'), |
||
| 52 | $config->get('influxdb-database') |
||
| 53 | ); |
||
| 54 | |||
| 55 | $lastDays = (int)$input->getOption('days') ? (int)$input->getOption('days') : 0; |
||
| 56 | $limit = (int)$input->getOption('limit') ? (int)$input->getOption('limit') : 0; |
||
| 57 | |||
| 58 | $torrentList = $client->getTorrentData(); |
||
| 59 | |||
| 60 | $torrentList = TorrentListUtils::filterTorrents($torrentList, [ |
||
| 61 | 'age' => $input->getOption('age'), |
||
| 62 | 'name' => $input->getOption('name'), |
||
| 63 | ]); |
||
| 64 | |||
| 65 | $transmissionHost = $config->overrideConfig($input, 'transmission-host'); |
||
| 66 | |||
| 67 | $rows = []; |
||
| 68 | |||
| 69 | foreach ($torrentList as $torrent) { |
||
| 70 | $perDay = $torrent['age'] ? |
||
| 71 | TorrentUtils::getSizeInGb($torrent[Torrent\Get::UPLOAD_EVER] / $torrent['age']) : 0; |
||
| 72 | $uploaded = $influxDbClient->getTorrentSum($torrent, 'uploaded_last', $transmissionHost, $lastDays); |
||
| 73 | |||
| 74 | $profit = round($uploaded / $torrent[Torrent\Get::TOTAL_SIZE], 2); |
||
| 75 | |||
| 76 | $rows[] = [ |
||
| 77 | $torrent[Torrent\Get::NAME], |
||
| 78 | $torrent[Torrent\Get::ID], |
||
| 79 | $torrent['age'], |
||
| 80 | TorrentUtils::getSizeInGb($torrent[Torrent\Get::TOTAL_SIZE]), |
||
| 81 | TorrentUtils::getSizeInGb($uploaded) . ' GB', |
||
| 82 | $perDay, |
||
| 83 | $profit |
||
| 84 | ]; |
||
| 85 | } |
||
| 86 | } catch (\Exception $e) { |
||
| 87 | $logger->critical($e->getMessage()); |
||
| 88 | return 1; |
||
| 89 | } |
||
| 90 | |||
| 91 | $rows = TableUtils::filterRows($rows, [ |
||
| 92 | '6' => ['type' => 'numeric', 'value' => $input->getOption('profit')] |
||
| 93 | ]); |
||
| 94 | |||
| 95 | TableUtils::printTable([ |
||
| 96 | 'headers' => ['Name', 'Id', 'Age', 'Size', 'Uploaded', 'Per day', 'Profit'], |
||
| 97 | 'rows' => $rows, |
||
| 98 | 'totals' => [ |
||
| 99 | '', |
||
| 100 | '', |
||
| 101 | '', |
||
| 102 | '', // TODO: cannot sum rendered size or unfiltered torrentList |
||
| 103 | TorrentListUtils::sumArrayField($rows, 4), |
||
| 104 | TorrentListUtils::sumArrayField($rows, 5), |
||
| 105 | TorrentListUtils::sumArrayField($rows, 6), |
||
| 106 | ] |
||
| 107 | ], $output, $input->getOption('sort'), $limit); |
||
| 108 | |||
| 109 | if ($input->getOption('rm')) { |
||
| 110 | return $this->removeTorrents($input, $output, $rows); |
||
| 111 | } |
||
| 112 | |||
| 113 | return 0; |
||
| 114 | } |
||
| 115 | |||
| 140 |