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