Conditions | 6 |
Paths | 35 |
Total Lines | 53 |
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 |
||
35 | protected function execute(InputInterface $input, OutputInterface $output) |
||
36 | { |
||
37 | $config = $this->getApplication()->getConfig(); |
||
38 | $logger = $this->getApplication()->getLogger(); |
||
39 | $client = $this->getApplication()->getClient(); |
||
40 | |||
41 | $torrentList = $client->getTorrentData(); |
||
42 | if (!$config->get('allow-duplicates')) { |
||
43 | $obsoleteList = TorrentListUtils::getObsoleteTorrents($torrentList); |
||
44 | if (!empty($obsoleteList)) { |
||
45 | $output->writeln('<comment>Found obsolete torrents, ' |
||
46 | . 'remove it using transmission-cli torrent-remove-duplicates</comment>'); |
||
47 | TorrentListUtils::printTorrentsTable($obsoleteList, $output); |
||
48 | return 1; |
||
49 | } |
||
50 | } |
||
51 | |||
52 | try { |
||
53 | $influxDbClient = $this->getApplication()->getInfluxDbClient( |
||
54 | $config->get('influxdb-host'), |
||
55 | $config->get('influxdb-port'), |
||
56 | $config->get('influxdb-user'), |
||
57 | $config->get('influxdb-password'), |
||
58 | $config->get('influxdb-database') |
||
59 | ); |
||
60 | |||
61 | $points = []; |
||
62 | |||
63 | $transmissionHost = $config->get('transmission-host'); |
||
64 | |||
65 | foreach ($torrentList as $torrent) { |
||
66 | $age = TorrentUtils::getTorrentAge($torrent); |
||
67 | $torrentPoint = $influxDbClient->buildPoint($torrent, $transmissionHost); |
||
68 | |||
69 | if ($age) { |
||
70 | $points[] = $torrentPoint; |
||
71 | } else { |
||
72 | $logger->debug('Skip point: {point}', ['point' => $torrentPoint]); |
||
73 | } |
||
74 | } |
||
75 | |||
76 | $points[] = $influxDbClient->buildStatus($torrentList, $transmissionHost); |
||
77 | |||
78 | $this->dryRun($input, $output, function () use ($influxDbClient, $points) { |
||
79 | $influxDbClient->writePoints($points); |
||
80 | }, 'dry-run, don\'t really send points'); |
||
81 | } catch (\Exception $e) { |
||
82 | $logger->critical($e->getMessage()); |
||
83 | return 1; |
||
84 | } |
||
85 | |||
86 | return 0; |
||
87 | } |
||
88 | } |
||
89 |