Conditions | 6 |
Paths | 8 |
Total Lines | 56 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
58 | public function getPopularTorrentsUrls(OutputInterface $output, WeburgClient $weburgClient, $downloadDir) |
||
59 | { |
||
60 | $torrentsUrls = []; |
||
61 | |||
62 | $config = $this->getApplication()->getConfig(); |
||
63 | $logger = $this->getApplication()->getLogger(); |
||
64 | |||
65 | $moviesIds = $weburgClient->getMoviesIds(); |
||
66 | |||
67 | $progress = new ProgressBar($output, count($moviesIds)); |
||
68 | $progress->start(); |
||
69 | |||
70 | foreach ($moviesIds as $movieId) { |
||
71 | $progress->setMessage('Check movie ' . $movieId . '...'); |
||
72 | $progress->advance(); |
||
73 | |||
74 | $downloadedLogfile = $downloadDir . '/' . $movieId; |
||
75 | |||
76 | $isDownloaded = file_exists($downloadedLogfile); |
||
77 | if ($isDownloaded) { |
||
78 | continue; |
||
79 | } |
||
80 | |||
81 | $movieInfo = $weburgClient->getMovieInfoById($movieId); |
||
82 | foreach (array_keys($movieInfo) as $infoField) { |
||
83 | if (!isset($movieInfo[$infoField])) { |
||
84 | $logger->warning('Cannot find ' . $infoField . ' in movie ' . $movieId); |
||
85 | } |
||
86 | } |
||
87 | |||
88 | $isTorrentPopular = $weburgClient->isTorrentPopular( |
||
89 | $movieInfo, |
||
90 | $config->get('download-comments-min'), |
||
91 | $config->get('download-imdb-min'), |
||
92 | $config->get('download-kinopoisk-min'), |
||
93 | $config->get('download-votes-min') |
||
94 | ); |
||
95 | |||
96 | if ($isTorrentPopular) { |
||
97 | $progress->setMessage('Download movie ' . $movieId . '...'); |
||
98 | |||
99 | $movieUrls = $weburgClient->getMovieTorrentUrlsById($movieId); |
||
100 | $torrentsUrls = array_merge($torrentsUrls, $movieUrls); |
||
101 | $logger->info('Download movie ' . $movieId . ': ' . $movieInfo['title']); |
||
102 | |||
103 | file_put_contents( |
||
104 | $downloadedLogfile, |
||
105 | date('Y-m-d H:i:s') . "\n" . implode("\n", $torrentsUrls) |
||
106 | ); |
||
107 | } |
||
108 | } |
||
109 | |||
110 | $progress->finish(); |
||
111 | |||
112 | return $torrentsUrls; |
||
113 | } |
||
114 | |||
177 |