Conditions | 6 |
Paths | 31 |
Total Lines | 67 |
Code Lines | 44 |
Lines | 0 |
Ratio | 0 % |
Changes | 8 | ||
Bugs | 2 | 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 |
||
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'] = round($torrent['uploaded'] / $torrent[Torrent\Get::TOTAL_SIZE] / $days * 100, 2); |
||
118 | |||
119 | return $torrent; |
||
120 | }, $torrentList); |
||
121 | } catch (\Exception $e) { |
||
122 | $logger->critical($e->getMessage()); |
||
123 | return 1; |
||
124 | } |
||
125 | |||
126 | $torrentList = TorrentListUtils::filterTorrents($torrentList, [ |
||
127 | 'profit' => ['type' => 'numeric', 'value' => $input->getOption('profit')] |
||
128 | ]); |
||
129 | |||
130 | $tableData = $this->buildTableData($torrentList, $input->getOption('sort'), $limit); |
||
131 | |||
132 | TableUtils::printTable($tableData, $output); |
||
133 | |||
134 | if ($input->getOption('rm')) { |
||
135 | return $this->removeTorrents($input, $output, $tableData['rows']); |
||
136 | } |
||
137 | |||
138 | return 0; |
||
139 | } |
||
140 | |||
199 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.