| Conditions | 5 |
| Paths | 4 |
| Total Lines | 57 |
| Code Lines | 32 |
| 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 |
||
| 25 | public function handle(): int |
||
| 26 | { |
||
| 27 | $videosId = (int) $this->argument('videos_id'); |
||
| 28 | $dryRun = (bool) $this->option('dry-run'); |
||
| 29 | |||
| 30 | // Validate target show exists and is TV type (0) |
||
| 31 | $video = Video::query()->where('id', $videosId)->where('type', 0)->first(['id', 'title']); |
||
| 32 | if ($video === null) { |
||
| 33 | $this->error("videos_id {$videosId} not found or is not a TV show (type=0)"); |
||
| 34 | |||
| 35 | return self::FAILURE; |
||
| 36 | } |
||
| 37 | |||
| 38 | // Gather releases to reset |
||
| 39 | $baseQuery = Release::query() |
||
| 40 | ->select(['id']) |
||
| 41 | ->where('videos_id', $videosId) |
||
| 42 | ->whereBetween('categories_id', [Category::TV_ROOT, Category::TV_OTHER]); |
||
| 43 | |||
| 44 | $total = (clone $baseQuery)->count(); |
||
| 45 | if ($total === 0) { |
||
| 46 | $this->info('No releases found for this videos_id in TV categories'); |
||
| 47 | |||
| 48 | return self::SUCCESS; |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($dryRun) { |
||
| 52 | $this->line("[Dry Run] Would reset {$total} release(s) for TV show: {$video->title} (videos_id={$videosId})"); |
||
| 53 | |||
| 54 | return self::SUCCESS; |
||
| 55 | } |
||
| 56 | |||
| 57 | $this->info("Resetting postprocessing for TV show: {$video->title} (videos_id={$videosId})"); |
||
| 58 | |||
| 59 | // Progress bar |
||
| 60 | $bar = $this->output->createProgressBar($total); |
||
|
|
|||
| 61 | $bar->setOverwrite(true); |
||
| 62 | $bar->start(); |
||
| 63 | |||
| 64 | // Chunk through releases to avoid loading all models simultaneously |
||
| 65 | $baseQuery->chunkById(1000, function ($chunk) use ($bar) { |
||
| 66 | foreach ($chunk as $release) { |
||
| 67 | Release::query()->where('id', $release->id)->update([ |
||
| 68 | // Reset association so TV pipeline picks them up again |
||
| 69 | 'videos_id' => 0, |
||
| 70 | 'tv_episodes_id' => 0, |
||
| 71 | ]); |
||
| 72 | $bar->advance(); |
||
| 73 | } |
||
| 74 | }); |
||
| 75 | |||
| 76 | $bar->finish(); |
||
| 77 | $this->newLine(); |
||
| 78 | $this->info(number_format($total).' release(s) reset. They will be considered for TV postprocessing again.'); |
||
| 79 | $this->line('You can now run: php artisan postprocess:tv-pipeline <guid-bucket> (or your existing TV processing routines)'); |
||
| 80 | |||
| 81 | return self::SUCCESS; |
||
| 82 | } |
||
| 84 |