| Conditions | 48 |
| Paths | > 20000 |
| Total Lines | 182 |
| Code Lines | 128 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 61 | public function processSite($groupID, $guidChar, $process, bool $local = false): void |
||
| 62 | { |
||
| 63 | $res = $this->getTvReleases($groupID, $guidChar, $process, parent::PROCESS_TVDB); |
||
| 64 | |||
| 65 | $tvCount = \count($res); |
||
| 66 | |||
| 67 | if ($tvCount === 0) { |
||
| 68 | return; |
||
| 69 | } |
||
| 70 | |||
| 71 | $this->titleCache = []; |
||
| 72 | $processed = 0; |
||
| 73 | $matched = 0; |
||
| 74 | $skipped = 0; |
||
| 75 | |||
| 76 | foreach ($res as $row) { |
||
| 77 | $processed++; |
||
| 78 | $siteId = false; |
||
| 79 | $this->posterUrl = ''; |
||
| 80 | |||
| 81 | $release = $this->parseInfo($row['searchname']); |
||
| 82 | if (\is_array($release) && $release['name'] !== '') { |
||
| 83 | if (\in_array($release['cleanname'], $this->titleCache, false)) { |
||
| 84 | if ($this->echooutput) { |
||
| 85 | cli()->primaryOver(' → '); |
||
| 86 | cli()->alternateOver($this->truncateTitle($release['cleanname'])); |
||
| 87 | cli()->primaryOver(' → '); |
||
| 88 | cli()->alternate('Skipped (previously failed)'); |
||
| 89 | } |
||
| 90 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
| 91 | $skipped++; |
||
| 92 | |||
| 93 | continue; |
||
| 94 | } |
||
| 95 | |||
| 96 | $videoId = $this->getByTitle($release['cleanname'], parent::TYPE_TV); |
||
| 97 | |||
| 98 | if ($videoId !== 0) { |
||
| 99 | $siteId = $this->getSiteByID('tvdb', $videoId); |
||
| 100 | } |
||
| 101 | |||
| 102 | $lookupSetting = true; |
||
| 103 | if ($local === true || $this->local) { |
||
| 104 | $lookupSetting = false; |
||
| 105 | } |
||
| 106 | |||
| 107 | if ($siteId === false && $lookupSetting) { |
||
| 108 | if ($this->echooutput) { |
||
| 109 | cli()->primaryOver(' → '); |
||
| 110 | cli()->headerOver($this->truncateTitle($release['cleanname'])); |
||
| 111 | cli()->primaryOver(' → '); |
||
| 112 | cli()->info('Searching TVDB...'); |
||
| 113 | } |
||
| 114 | |||
| 115 | $country = ( |
||
| 116 | isset($release['country']) && \strlen($release['country']) === 2 |
||
| 117 | ? (string) $release['country'] |
||
| 118 | : '' |
||
| 119 | ); |
||
| 120 | |||
| 121 | $tvdbShow = $this->getShowInfo((string) $release['cleanname']); |
||
| 122 | |||
| 123 | if (\is_array($tvdbShow)) { |
||
| 124 | $tvdbShow['country'] = $country; |
||
| 125 | $videoId = $this->add($tvdbShow); |
||
| 126 | $siteId = (int) $tvdbShow['tvdb']; |
||
| 127 | } |
||
| 128 | } elseif ($this->echooutput && $siteId !== false) { |
||
| 129 | cli()->primaryOver(' → '); |
||
| 130 | cli()->headerOver($this->truncateTitle($release['cleanname'])); |
||
| 131 | cli()->primaryOver(' → '); |
||
| 132 | cli()->info('Found in DB'); |
||
| 133 | } |
||
| 134 | |||
| 135 | if ((int) $videoId > 0 && (int) $siteId > 0) { |
||
| 136 | if (! empty($tvdbShow['poster'])) { |
||
| 137 | $this->getPoster($videoId); |
||
| 138 | } elseif ($this->fanart->isConfigured()) { |
||
| 139 | $posterUrl = $this->fanart->getBestTvPoster($siteId); |
||
| 140 | if (! empty($posterUrl)) { |
||
| 141 | $this->posterUrl = $posterUrl; |
||
| 142 | $this->getPoster($videoId); |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | $seriesNo = (! empty($release['season']) ? preg_replace('/^S0*/i', '', $release['season']) : ''); |
||
| 147 | $episodeNo = (! empty($release['episode']) ? preg_replace('/^E0*/i', '', $release['episode']) : ''); |
||
| 148 | $hasAirdate = ! empty($release['airdate']); |
||
| 149 | |||
| 150 | if ($episodeNo === 'all') { |
||
| 151 | $this->setVideoIdFound($videoId, $row['id'], 0); |
||
| 152 | if ($this->echooutput) { |
||
| 153 | cli()->primaryOver(' → '); |
||
| 154 | cli()->headerOver($this->truncateTitle($release['cleanname'])); |
||
| 155 | cli()->primaryOver(' → '); |
||
| 156 | cli()->primary('Full Season matched'); |
||
| 157 | } |
||
| 158 | $matched++; |
||
| 159 | |||
| 160 | continue; |
||
| 161 | } |
||
| 162 | |||
| 163 | if (! $this->countEpsByVideoID($videoId)) { |
||
| 164 | $this->getEpisodeInfo($siteId, -1, -1, $videoId); |
||
| 165 | } |
||
| 166 | |||
| 167 | $episode = $this->getBySeasonEp($videoId, $seriesNo, $episodeNo, $release['airdate']); |
||
| 168 | |||
| 169 | if ($episode === false && $lookupSetting) { |
||
| 170 | if ($seriesNo !== '' && $episodeNo !== '') { |
||
| 171 | $tvdbEpisode = $this->getEpisodeInfo($siteId, (int) $seriesNo, (int) $episodeNo, $videoId); |
||
| 172 | if ($tvdbEpisode) { |
||
|
|
|||
| 173 | $episode = $this->addEpisode($videoId, $tvdbEpisode); |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | if ($episode === false && $hasAirdate) { |
||
| 178 | $this->getEpisodeInfo($siteId, -1, -1, $videoId); |
||
| 179 | $episode = $this->getBySeasonEp($videoId, 0, 0, $release['airdate']); |
||
| 180 | } |
||
| 181 | } |
||
| 182 | |||
| 183 | if ($episode !== false && is_numeric($episode) && $episode > 0) { |
||
| 184 | $this->setVideoIdFound($videoId, $row['id'], $episode); |
||
| 185 | if ($this->echooutput) { |
||
| 186 | cli()->primaryOver(' → '); |
||
| 187 | cli()->headerOver($this->truncateTitle($release['cleanname'])); |
||
| 188 | if ($seriesNo !== '' && $episodeNo !== '') { |
||
| 189 | cli()->primaryOver(' S'); |
||
| 190 | cli()->warningOver(sprintf('%02d', $seriesNo)); |
||
| 191 | cli()->primaryOver('E'); |
||
| 192 | cli()->warningOver(sprintf('%02d', $episodeNo)); |
||
| 193 | } elseif ($hasAirdate) { |
||
| 194 | cli()->primaryOver(' | '); |
||
| 195 | cli()->warningOver($release['airdate']); |
||
| 196 | } |
||
| 197 | cli()->primaryOver(' ✓ '); |
||
| 198 | cli()->primary('MATCHED (TVDB)'); |
||
| 199 | } |
||
| 200 | $matched++; |
||
| 201 | } else { |
||
| 202 | $this->setVideoIdFound($videoId, $row['id'], 0); |
||
| 203 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
| 204 | if ($this->echooutput) { |
||
| 205 | cli()->primaryOver(' → '); |
||
| 206 | cli()->alternateOver($this->truncateTitle($release['cleanname'])); |
||
| 207 | if ($hasAirdate) { |
||
| 208 | cli()->primaryOver(' | '); |
||
| 209 | cli()->warningOver($release['airdate']); |
||
| 210 | } |
||
| 211 | cli()->primaryOver(' → '); |
||
| 212 | cli()->warning('Episode not found'); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | } else { |
||
| 216 | $this->setVideoNotFound(parent::PROCESS_TVMAZE, $row['id']); |
||
| 217 | $this->titleCache[] = $release['cleanname'] ?? null; |
||
| 218 | if ($this->echooutput) { |
||
| 219 | cli()->primaryOver(' → '); |
||
| 220 | cli()->alternateOver($this->truncateTitle($release['cleanname'])); |
||
| 221 | cli()->primaryOver(' → '); |
||
| 222 | cli()->warning('Not found'); |
||
| 223 | } |
||
| 224 | } |
||
| 225 | } else { |
||
| 226 | $this->setVideoNotFound(parent::FAILED_PARSE, $row['id']); |
||
| 227 | $this->titleCache[] = $release['cleanname'] ?? null; |
||
| 228 | if ($this->echooutput) { |
||
| 229 | cli()->error(sprintf( |
||
| 230 | ' ✗ [%d/%d] Parse failed: %s', |
||
| 231 | $processed, |
||
| 232 | $tvCount, |
||
| 233 | mb_substr($row['searchname'], 0, 50) |
||
| 234 | )); |
||
| 235 | } |
||
| 236 | } |
||
| 237 | } |
||
| 238 | |||
| 239 | if ($this->echooutput && $matched > 0) { |
||
| 240 | echo "\n"; |
||
| 241 | cli()->primaryOver(' ✓ TVDB: '); |
||
| 242 | cli()->primary(sprintf('%d matched, %d skipped', $matched, $skipped)); |
||
| 243 | } |
||
| 518 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.