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