| Conditions | 8 |
| Paths | 31 |
| Total Lines | 71 |
| 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 |
||
| 73 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 74 | { |
||
| 75 | $config = $this->getApplication()->getConfig(); |
||
| 76 | $logger = $this->getApplication()->getLogger(); |
||
| 77 | $client = $this->getApplication()->getClient(); |
||
| 78 | |||
| 79 | try { |
||
| 80 | $influxDbClient = $this->getApplication()->getInfluxDbClient( |
||
| 81 | $config->get('influxdb-host'), |
||
| 82 | $config->get('influxdb-port'), |
||
| 83 | $config->get('influxdb-user'), |
||
| 84 | $config->get('influxdb-password'), |
||
| 85 | $config->get('influxdb-database') |
||
| 86 | ); |
||
| 87 | |||
| 88 | $lastDays = (int)$input->getOption('days') ? (int)$input->getOption('days') : 0; |
||
| 89 | $limit = (int)$input->getOption('limit') ? (int)$input->getOption('limit') : 0; |
||
| 90 | |||
| 91 | $torrentList = $client->getTorrentData(); |
||
| 92 | |||
| 93 | $torrentList = array_map(function ($torrent) { |
||
| 94 | $torrent['age'] = TorrentUtils::getTorrentAgeInDays($torrent); |
||
| 95 | return $torrent; |
||
| 96 | }, $torrentList); |
||
| 97 | |||
| 98 | $torrentList = TorrentListUtils::filterTorrents($torrentList, [ |
||
| 99 | 'age' => $input->getOption('age'), |
||
| 100 | 'name' => $input->getOption('name'), |
||
| 101 | ]); |
||
| 102 | |||
| 103 | $transmissionHost = $config->get('transmission-host'); |
||
| 104 | |||
| 105 | $torrentList = array_map(function ($torrent) use ($influxDbClient, $transmissionHost, $lastDays) { |
||
| 106 | $torrent['uploaded'] = $influxDbClient->getTorrentSum( |
||
| 107 | $torrent, |
||
| 108 | 'uploaded_last', |
||
| 109 | $transmissionHost, |
||
| 110 | $lastDays |
||
| 111 | ); |
||
| 112 | |||
| 113 | $days = max(1, min($torrent['age'], $lastDays)); |
||
| 114 | $torrent['per_day'] = $days ? |
||
| 115 | TorrentUtils::getSizeInGb($torrent['uploaded'] / $days) : 0; |
||
| 116 | |||
| 117 | $torrent['profit'] = $torrent[Torrent\Get::TOTAL_SIZE] ? |
||
| 118 | round($torrent['uploaded'] / $torrent[Torrent\Get::TOTAL_SIZE] / $days * 100, 2) : 0; |
||
| 119 | |||
| 120 | return $torrent; |
||
| 121 | }, $torrentList); |
||
| 122 | } catch (\Exception $e) { |
||
| 123 | $logger->critical($e->getMessage()); |
||
| 124 | return 1; |
||
| 125 | } |
||
| 126 | |||
| 127 | $torrentList = TorrentListUtils::filterTorrents($torrentList, [ |
||
| 128 | 'profit' => ['type' => 'numeric', 'value' => $input->getOption('profit')] |
||
| 129 | ]); |
||
| 130 | |||
| 131 | $tableData = $this->buildTableData($torrentList, $input->getOption('sort'), $limit); |
||
| 132 | |||
| 133 | TableUtils::printTable($tableData, $output); |
||
| 134 | |||
| 135 | $freeSpace = $client->getFreeSpace(); |
||
| 136 | $output->writeln('Free space: ' . TorrentUtils::getSizeInGb($freeSpace) . ' GB'); |
||
| 137 | |||
| 138 | if ($input->getOption('rm') && count($torrentList) > 0) { |
||
| 139 | return $this->removeTorrents($input, $output, $tableData['rows']); |
||
| 140 | } |
||
| 141 | |||
| 142 | return 0; |
||
| 143 | } |
||
| 144 | |||
| 195 |