Conditions | 5 |
Paths | 39 |
Total Lines | 55 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
34 | protected function execute(InputInterface $input, OutputInterface $output) |
||
35 | { |
||
36 | $config = $this->getApplication()->getConfig(); |
||
37 | $logger = $this->getApplication()->getLogger(); |
||
38 | $client = $this->getApplication()->getClient(); |
||
39 | |||
40 | try { |
||
41 | $influxDbClient = $this->getApplication()->getInfluxDbClient( |
||
42 | $config->get('influxdb-host'), |
||
43 | $config->get('influxdb-port'), |
||
44 | $config->get('influxdb-user'), |
||
45 | $config->get('influxdb-password'), |
||
46 | $config->get('influxdb-database') |
||
47 | ); |
||
48 | |||
49 | $lastDays = (int)$input->getOption('days') ? (int)$input->getOption('days') : 0; |
||
50 | $limit = (int)$input->getOption('limit') ? (int)$input->getOption('limit') : 0; |
||
51 | |||
52 | $torrentList = $client->getTorrentData(); |
||
53 | |||
54 | $torrentList = TorrentListUtils::filterTorrents($torrentList, [ |
||
55 | 'name' => $input->getOption('name'), |
||
56 | ]); |
||
57 | |||
58 | $transmissionHost = $config->overrideConfig($input, 'transmission-host'); |
||
59 | |||
60 | $rows = []; |
||
61 | |||
62 | foreach ($torrentList as $torrent) { |
||
63 | $uploaded = $influxDbClient->getTorrentSum($torrent, 'uploaded_last', $transmissionHost, $lastDays); |
||
64 | |||
65 | $profit = round($uploaded / $torrent[Torrent\Get::TOTAL_SIZE], 2); |
||
66 | |||
67 | $rows[] = [ |
||
68 | $torrent[Torrent\Get::NAME], |
||
69 | TorrentUtils::getSizeInGb($uploaded) . ' GB', |
||
70 | $profit |
||
71 | ]; |
||
72 | } |
||
73 | } catch (\Exception $e) { |
||
74 | $logger->critical($e->getMessage()); |
||
75 | return 1; |
||
76 | } |
||
77 | |||
78 | $rows = TorrentListUtils::filterRows($rows, [ |
||
79 | '2' => ['type' => 'numeric', 'value' => $input->getOption('profit')] |
||
80 | ]); |
||
81 | |||
82 | TorrentListUtils::printTable([ |
||
83 | 'headers' => ['Name', 'Uploaded', 'Profit'], |
||
84 | 'rows' => $rows |
||
85 | ], $output, $input->getOption('sort'), $limit); |
||
86 | |||
87 | return 0; |
||
88 | } |
||
89 | } |
||
90 |