| Conditions | 35 |
| Paths | 2078 |
| Total Lines | 180 |
| Code Lines | 97 |
| 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 |
||
| 67 | protected function processStandard(int $maxPerRun): int |
||
| 68 | { |
||
| 69 | $guidChar = $this->option('guid-char'); |
||
| 70 | |||
| 71 | if ($guidChar === null) { |
||
|
|
|||
| 72 | $this->error('--guid-char is required for standard type'); |
||
| 73 | |||
| 74 | return Command::FAILURE; |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->info("Processing releases with GUID starting with: {$guidChar}"); |
||
| 78 | $this->info("Maximum per run: {$maxPerRun}"); |
||
| 79 | |||
| 80 | // Allow for larger filename return sets |
||
| 81 | DB::statement('SET SESSION group_concat_max_len = 65536'); |
||
| 82 | |||
| 83 | // Find releases to process |
||
| 84 | $releases = $this->fetchReleases($guidChar, $maxPerRun); |
||
| 85 | |||
| 86 | if ($releases->isEmpty()) { |
||
| 87 | $this->info('No releases to process'); |
||
| 88 | |||
| 89 | return Command::SUCCESS; |
||
| 90 | } |
||
| 91 | |||
| 92 | $this->info("Found {$releases->count()} releases to process"); |
||
| 93 | $bar = $this->output->createProgressBar($releases->count()); |
||
| 94 | $bar->start(); |
||
| 95 | |||
| 96 | $nntp = null; |
||
| 97 | $nzbcontents = null; |
||
| 98 | |||
| 99 | foreach ($releases as $release) { |
||
| 100 | $this->checked++; |
||
| 101 | $this->nameFixer->reset(); |
||
| 102 | |||
| 103 | // Process UID |
||
| 104 | if ((int) $release->proc_uid === NameFixer::PROC_UID_NONE && |
||
| 105 | (! empty($release->uid) || ! empty($release->mediainfo))) { |
||
| 106 | |||
| 107 | if (! empty($release->uid)) { |
||
| 108 | $this->nameFixer->checkName($release, true, 'UID, ', 1, true); |
||
| 109 | } |
||
| 110 | |||
| 111 | if (empty($this->nameFixer->matched) && ! empty($release->mediainfo)) { |
||
| 112 | $this->nameFixer->checkName($release, true, 'Mediainfo, ', 1, true); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | $this->nameFixer->_updateSingleColumn('proc_uid', NameFixer::PROC_UID_DONE, $release->releases_id); |
||
| 117 | |||
| 118 | if ($this->nameFixer->matched) { |
||
| 119 | $bar->advance(); |
||
| 120 | |||
| 121 | continue; |
||
| 122 | } |
||
| 123 | |||
| 124 | // Process CRC32 |
||
| 125 | if ((int) $release->proc_crc32 === NameFixer::PROC_CRC_NONE && ! empty($release->crc)) { |
||
| 126 | $this->nameFixer->reset(); |
||
| 127 | $this->nameFixer->checkName($release, true, 'CRC32, ', 1, true); |
||
| 128 | } |
||
| 129 | |||
| 130 | $this->nameFixer->_updateSingleColumn('proc_crc32', NameFixer::PROC_CRC_DONE, $release->releases_id); |
||
| 131 | |||
| 132 | if ($this->nameFixer->matched) { |
||
| 133 | $bar->advance(); |
||
| 134 | |||
| 135 | continue; |
||
| 136 | } |
||
| 137 | |||
| 138 | // Process SRR |
||
| 139 | if ((int) $release->proc_srr === NameFixer::PROC_SRR_NONE) { |
||
| 140 | $this->nameFixer->reset(); |
||
| 141 | $this->nameFixer->checkName($release, true, 'SRR, ', 1, true); |
||
| 142 | } |
||
| 143 | |||
| 144 | $this->nameFixer->_updateSingleColumn('proc_srr', NameFixer::PROC_SRR_DONE, $release->releases_id); |
||
| 145 | |||
| 146 | if ($this->nameFixer->matched) { |
||
| 147 | $bar->advance(); |
||
| 148 | |||
| 149 | continue; |
||
| 150 | } |
||
| 151 | |||
| 152 | // Process PAR2 hash |
||
| 153 | if ((int) $release->proc_hash16k === NameFixer::PROC_HASH16K_NONE && ! empty($release->hash)) { |
||
| 154 | $this->nameFixer->reset(); |
||
| 155 | $this->nameFixer->checkName($release, true, 'PAR2 hash, ', 1, true); |
||
| 156 | } |
||
| 157 | |||
| 158 | $this->nameFixer->_updateSingleColumn('proc_hash16k', NameFixer::PROC_HASH16K_DONE, $release->releases_id); |
||
| 159 | |||
| 160 | if ($this->nameFixer->matched) { |
||
| 161 | $bar->advance(); |
||
| 162 | |||
| 163 | continue; |
||
| 164 | } |
||
| 165 | |||
| 166 | // Process NFO |
||
| 167 | if ((int) $release->nfostatus === Nfo::NFO_FOUND && |
||
| 168 | (int) $release->proc_nfo === NameFixer::PROC_NFO_NONE && |
||
| 169 | ! empty($release->textstring) && |
||
| 170 | ! preg_match('/^=newz\[NZB\]=\w+/', $release->textstring)) { |
||
| 171 | |||
| 172 | $this->nameFixer->reset(); |
||
| 173 | $this->nameFixer->checkName($release, true, 'NFO, ', 1, true); |
||
| 174 | } |
||
| 175 | |||
| 176 | $this->nameFixer->_updateSingleColumn('proc_nfo', NameFixer::PROC_NFO_DONE, $release->releases_id); |
||
| 177 | |||
| 178 | if ($this->nameFixer->matched) { |
||
| 179 | $bar->advance(); |
||
| 180 | |||
| 181 | continue; |
||
| 182 | } |
||
| 183 | |||
| 184 | // Process filenames |
||
| 185 | if ((int) $release->fileid > 0 && (int) $release->proc_files === NameFixer::PROC_FILES_NONE) { |
||
| 186 | $this->nameFixer->reset(); |
||
| 187 | $fileNames = explode('|', $release->filestring); |
||
| 188 | |||
| 189 | if (is_array($fileNames)) { |
||
| 190 | $releaseFile = $release; |
||
| 191 | foreach ($fileNames as $fileName) { |
||
| 192 | if ($this->nameFixer->matched === false) { |
||
| 193 | $releaseFile->textstring = $fileName; |
||
| 194 | $this->nameFixer->checkName($releaseFile, true, 'Filenames, ', 1, true); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | } |
||
| 198 | } |
||
| 199 | |||
| 200 | $this->nameFixer->_updateSingleColumn('proc_files', NameFixer::PROC_FILES_DONE, $release->releases_id); |
||
| 201 | |||
| 202 | if ($this->nameFixer->matched) { |
||
| 203 | $bar->advance(); |
||
| 204 | |||
| 205 | continue; |
||
| 206 | } |
||
| 207 | |||
| 208 | // Process PAR2 |
||
| 209 | if ((int) $release->proc_par2 === NameFixer::PROC_PAR2_NONE) { |
||
| 210 | // Initialize NZB contents if needed |
||
| 211 | if (! isset($nzbcontents)) { |
||
| 212 | $nntp = new NNTP; |
||
| 213 | $compressedHeaders = config('nntmux_nntp.compressed_headers'); |
||
| 214 | |||
| 215 | if ((config('nntmux_nntp.use_alternate_nntp_server') === true |
||
| 216 | ? $nntp->doConnect($compressedHeaders, true) |
||
| 217 | : $nntp->doConnect()) !== true) { |
||
| 218 | $this->warn('Unable to connect to usenet for PAR2 processing'); |
||
| 219 | } else { |
||
| 220 | $Nfo = new Nfo; |
||
| 221 | $nzbcontents = new NZBContents([ |
||
| 222 | 'Echo' => false, |
||
| 223 | 'NNTP' => $nntp, |
||
| 224 | 'Nfo' => $Nfo, |
||
| 225 | 'PostProcess' => new PostProcess(['Nfo' => $Nfo, 'NameFixer' => $this->nameFixer]), |
||
| 226 | ]); |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | if (isset($nzbcontents)) { |
||
| 231 | $nzbcontents->checkPAR2($release->guid, $release->releases_id, $release->groups_id, 1, true); |
||
| 232 | } |
||
| 233 | } |
||
| 234 | |||
| 235 | $this->nameFixer->_updateSingleColumn('proc_par2', NameFixer::PROC_PAR2_DONE, $release->releases_id); |
||
| 236 | |||
| 237 | $bar->advance(); |
||
| 238 | } |
||
| 239 | |||
| 240 | $bar->finish(); |
||
| 241 | $this->newLine(2); |
||
| 242 | |||
| 243 | $this->info("✅ Processed {$this->checked} releases"); |
||
| 244 | $this->info("✅ Fixed {$this->nameFixer->fixed} release names"); |
||
| 245 | |||
| 246 | return Command::SUCCESS; |
||
| 247 | } |
||
| 370 |