| Conditions | 26 |
| Paths | 10396 |
| Total Lines | 139 |
| Code Lines | 89 |
| 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 |
||
| 254 | public function getAudioInfo( |
||
| 255 | string $fileLocation, |
||
| 256 | string $fileExtension, |
||
| 257 | ReleaseProcessingContext $context, |
||
| 258 | string $tmpPath |
||
| 259 | ): array { |
||
| 260 | $result = ['audioInfo' => false, 'audioSample' => false]; |
||
| 261 | |||
| 262 | if (! $this->config->processAudioSample) { |
||
| 263 | $result['audioSample'] = true; |
||
| 264 | } |
||
| 265 | if (! $this->config->processAudioInfo) { |
||
| 266 | $result['audioInfo'] = true; |
||
| 267 | } |
||
| 268 | |||
| 269 | $rQuery = Release::query() |
||
| 270 | ->where('proc_pp', '=', 0) |
||
| 271 | ->where('id', $context->release->id) |
||
| 272 | ->select(['searchname', 'fromname', 'categories_id', 'groups_id']) |
||
| 273 | ->first(); |
||
| 274 | |||
| 275 | $musicParent = (string) Category::MUSIC_ROOT; |
||
| 276 | if ($rQuery === null || ! preg_match( |
||
| 277 | sprintf( |
||
| 278 | '/%d\d{3}|%d|%d|%d/', |
||
| 279 | $musicParent[0], |
||
| 280 | Category::OTHER_MISC, |
||
| 281 | Category::MOVIE_OTHER, |
||
| 282 | Category::TV_OTHER |
||
| 283 | ), |
||
| 284 | $rQuery->categories_id |
||
| 285 | )) { |
||
| 286 | return $result; |
||
| 287 | } |
||
| 288 | |||
| 289 | if (! File::isFile($fileLocation)) { |
||
| 290 | return $result; |
||
| 291 | } |
||
| 292 | |||
| 293 | // Get media info |
||
| 294 | if (! $result['audioInfo']) { |
||
| 295 | try { |
||
| 296 | $xmlArray = $this->mediaInfo()->getInfo($fileLocation, false); |
||
| 297 | if ($xmlArray !== null) { |
||
| 298 | foreach ($xmlArray->getAudios() as $track) { |
||
| 299 | if ($track->get('album') !== null && $track->get('performer') !== null) { |
||
| 300 | if ((int) $context->release->predb_id === 0 && $this->config->renameMusicMediaInfo) { |
||
| 301 | $ext = strtoupper($fileExtension); |
||
| 302 | |||
| 303 | $newName = $track->get('performer')->getFullName().' - '.$track->get('album')->getFullName(); |
||
| 304 | if (! empty($track->get('recorded_date')) |
||
| 305 | && preg_match('/(?:19|20)\d\d/', $track->get('recorded_date')->getFullname, $Year) |
||
| 306 | ) { |
||
| 307 | $newName .= ' ('.$Year[0].') '.$ext; |
||
| 308 | } else { |
||
| 309 | $newName .= ' '.$ext; |
||
| 310 | } |
||
| 311 | |||
| 312 | $newCat = match ($ext) { |
||
| 313 | 'MP3' => Category::MUSIC_MP3, |
||
| 314 | 'FLAC' => Category::MUSIC_LOSSLESS, |
||
| 315 | default => $this->categorize->determineCategory($rQuery->groups_id, $newName, $rQuery->fromname), |
||
| 316 | }; |
||
| 317 | |||
| 318 | $newTitle = escapeString(substr($newName, 0, 255)); |
||
| 319 | Release::whereId($context->release->id)->update([ |
||
| 320 | 'searchname' => $newTitle, |
||
| 321 | 'categories_id' => is_array($newCat) ? $newCat['categories_id'] : $newCat, |
||
| 322 | 'iscategorized' => 1, |
||
| 323 | 'isrenamed' => 1, |
||
| 324 | 'proc_pp' => 1, |
||
| 325 | ]); |
||
| 326 | |||
| 327 | if ($this->config->elasticsearchEnabled) { |
||
| 328 | $this->elasticsearch()->updateRelease($context->release->id); |
||
| 329 | } else { |
||
| 330 | $this->manticore()->updateRelease($context->release->id); |
||
| 331 | } |
||
| 332 | |||
| 333 | if ($this->config->echoCLI) { |
||
| 334 | NameFixer::echoChangedReleaseName([ |
||
| 335 | 'new_name' => $newTitle, |
||
| 336 | 'old_name' => $rQuery->searchname, |
||
| 337 | 'new_category' => $newCat, |
||
| 338 | 'old_category' => $rQuery->categories_id, |
||
| 339 | 'group' => $rQuery->groups_id, |
||
| 340 | 'releases_id' => $context->release->id, |
||
| 341 | 'method' => 'MediaExtractionService->getAudioInfo', |
||
| 342 | ]); |
||
| 343 | } |
||
| 344 | } |
||
| 345 | |||
| 346 | $this->releaseExtra->addFromXml($context->release->id, $xmlArray); |
||
| 347 | $result['audioInfo'] = true; |
||
| 348 | $context->foundAudioInfo = true; |
||
| 349 | break; |
||
| 350 | } |
||
| 351 | } |
||
| 352 | } |
||
| 353 | } catch (\Throwable $e) { |
||
| 354 | Log::debug($e->getMessage()); |
||
| 355 | } |
||
| 356 | } |
||
| 357 | |||
| 358 | // Create audio sample |
||
| 359 | if (! $result['audioSample']) { |
||
| 360 | $audioFileName = $context->release->guid.'.ogg'; |
||
| 361 | |||
| 362 | try { |
||
| 363 | if ($this->ffprobe()->isValid($fileLocation)) { |
||
| 364 | $audioSample = $this->ffmpeg()->open($fileLocation); |
||
| 365 | $format = new Vorbis(); |
||
| 366 | $audioSample->clip(TimeCode::fromSeconds(30), TimeCode::fromSeconds(30)); |
||
| 367 | $audioSample->save($format, $tmpPath.$audioFileName); |
||
| 368 | } |
||
| 369 | } catch (\Throwable $e) { |
||
| 370 | if ($this->config->debugMode) { |
||
| 371 | Log::error($e->getTraceAsString()); |
||
| 372 | } |
||
| 373 | } |
||
| 374 | |||
| 375 | if (File::isFile($tmpPath.$audioFileName)) { |
||
| 376 | $renamed = File::move($tmpPath.$audioFileName, $this->config->audioSavePath.$audioFileName); |
||
| 377 | if (! $renamed) { |
||
| 378 | $copied = File::copy($tmpPath.$audioFileName, $this->config->audioSavePath.$audioFileName); |
||
| 379 | File::delete($tmpPath.$audioFileName); |
||
| 380 | if (! $copied) { |
||
| 381 | return $result; |
||
| 382 | } |
||
| 383 | } |
||
| 384 | |||
| 385 | @chmod($this->config->audioSavePath.$audioFileName, 0764); |
||
| 386 | Release::query()->where('id', $context->release->id)->update(['audiostatus' => 1]); |
||
| 387 | $result['audioSample'] = true; |
||
| 388 | $context->foundAudioSample = true; |
||
| 389 | } |
||
| 390 | } |
||
| 391 | |||
| 392 | return $result; |
||
| 393 | } |
||
| 491 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths