| Conditions | 15 |
| Paths | 12 |
| Total Lines | 79 |
| Code Lines | 50 |
| 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 |
||
| 40 | protected function process(TvProcessingPassable $passable): TvProcessingResult |
||
| 41 | { |
||
| 42 | $parsedInfo = $passable->getParsedInfo(); |
||
| 43 | $context = $passable->context; |
||
| 44 | |||
| 45 | if ($parsedInfo === null || empty($parsedInfo['cleanname'])) { |
||
| 46 | return TvProcessingResult::notFound($this->getName()); |
||
| 47 | } |
||
| 48 | |||
| 49 | $cleanName = $parsedInfo['cleanname']; |
||
| 50 | $localDb = $this->getLocalDb(); |
||
| 51 | |||
| 52 | // Try to find the show in our local database by title |
||
| 53 | $videoId = $localDb->getByTitle($cleanName, TV::TYPE_TV, 0); |
||
| 54 | |||
| 55 | if ($videoId === 0 || $videoId === false) { |
||
| 56 | $this->outputNotFound($cleanName); |
||
| 57 | return TvProcessingResult::notFound($this->getName(), ['title' => $cleanName]); |
||
| 58 | } |
||
| 59 | |||
| 60 | // Found a matching show in local DB |
||
| 61 | $episodeId = false; |
||
| 62 | $hasEpisodeNumbers = $this->hasEpisodeNumbers($parsedInfo); |
||
| 63 | $hasAirdate = ! empty($parsedInfo['airdate']); |
||
| 64 | |||
| 65 | if ($hasEpisodeNumbers || $hasAirdate) { |
||
| 66 | // Try to find the specific episode |
||
| 67 | $episodeId = $localDb->getBySeasonEp( |
||
| 68 | $videoId, |
||
| 69 | (int) ($parsedInfo['season'] ?? 0), |
||
| 70 | (int) ($parsedInfo['episode'] ?? 0), |
||
| 71 | $parsedInfo['airdate'] ?? '' |
||
| 72 | ); |
||
| 73 | } |
||
| 74 | |||
| 75 | if ($episodeId !== false && $episodeId > 0) { |
||
| 76 | // Complete match - both show and episode found |
||
| 77 | $localDb->setVideoIdFound($videoId, $context->releaseId, $episodeId); |
||
| 78 | |||
| 79 | $this->outputMatch( |
||
| 80 | $cleanName, |
||
| 81 | $hasEpisodeNumbers ? (int) $parsedInfo['season'] : null, |
||
| 82 | $hasEpisodeNumbers ? (int) $parsedInfo['episode'] : null, |
||
| 83 | $hasAirdate ? $parsedInfo['airdate'] : null |
||
| 84 | ); |
||
| 85 | |||
| 86 | return TvProcessingResult::matched($videoId, $episodeId, $this->getName()); |
||
| 87 | } |
||
| 88 | |||
| 89 | // Series matched but no specific episode located |
||
| 90 | // Set video ID but mark episode as 0 (needs further lookup) |
||
| 91 | $localDb->setVideoIdFound($videoId, $context->releaseId, 0); |
||
| 92 | |||
| 93 | if ($this->echoOutput) { |
||
| 94 | $this->colorCli->primaryOver(' → '); |
||
| 95 | $this->colorCli->headerOver($this->truncateTitle($cleanName)); |
||
| 96 | if ($hasAirdate) { |
||
| 97 | $this->colorCli->primaryOver(' | '); |
||
| 98 | $this->colorCli->warningOver($parsedInfo['airdate']); |
||
| 99 | $this->colorCli->headerOver(' → '); |
||
| 100 | $this->colorCli->notice('Series matched, airdate not in local DB'); |
||
| 101 | } elseif ($hasEpisodeNumbers) { |
||
| 102 | $this->colorCli->primaryOver(' S'); |
||
| 103 | $this->colorCli->warningOver(sprintf('%02d', (int) $parsedInfo['season'])); |
||
| 104 | $this->colorCli->primaryOver('E'); |
||
| 105 | $this->colorCli->warningOver(sprintf('%02d', (int) $parsedInfo['episode'])); |
||
| 106 | $this->colorCli->headerOver(' → '); |
||
| 107 | $this->colorCli->notice('Series matched, episode not in local DB'); |
||
| 108 | } else { |
||
| 109 | $this->colorCli->primaryOver(' → '); |
||
| 110 | $this->colorCli->notice('Series matched (no episode info)'); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | // Return not found so external APIs can try to get the episode |
||
| 115 | return TvProcessingResult::notFound($this->getName(), [ |
||
| 116 | 'video_id' => $videoId, |
||
| 117 | 'series_matched' => true, |
||
| 118 | 'episode_missing' => true, |
||
| 119 | ]); |
||
| 133 |