| Conditions | 10 |
| Paths | 205 |
| Total Lines | 81 |
| Code Lines | 55 |
| 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 |
||
| 41 | public function handle(): int |
||
| 42 | { |
||
| 43 | $guid = $this->argument('guid'); |
||
| 44 | $reset = $this->option('reset'); |
||
| 45 | $debug = $this->option('debug'); |
||
| 46 | |||
| 47 | // Find the release by GUID |
||
| 48 | $release = Release::query()->where('guid', $guid)->first(); |
||
| 49 | |||
| 50 | if ($release === null) { |
||
| 51 | $this->error("Release with GUID '{$guid}' not found."); |
||
| 52 | return self::FAILURE; |
||
| 53 | } |
||
| 54 | |||
| 55 | $this->info('Found release:'); |
||
| 56 | $this->table( |
||
| 57 | ['ID', 'GUID', 'Search Name', 'Videos ID', 'Episode ID', 'Category'], |
||
| 58 | [[ |
||
| 59 | $release->id, |
||
| 60 | $release->guid, |
||
|
|
|||
| 61 | mb_substr($release->searchname, 0, 60) . (strlen($release->searchname) > 60 ? '...' : ''), |
||
| 62 | $release->videos_id, |
||
| 63 | $release->tv_episodes_id, |
||
| 64 | $release->categories_id, |
||
| 65 | ]] |
||
| 66 | ); |
||
| 67 | |||
| 68 | if ($reset) { |
||
| 69 | $this->warn('Resetting videos_id and tv_episodes_id to 0...'); |
||
| 70 | $release->update([ |
||
| 71 | 'videos_id' => 0, |
||
| 72 | 'tv_episodes_id' => 0, |
||
| 73 | ]); |
||
| 74 | $release->refresh(); |
||
| 75 | } |
||
| 76 | |||
| 77 | $this->info('Processing release through TV pipeline...'); |
||
| 78 | $this->newLine(); |
||
| 79 | |||
| 80 | try { |
||
| 81 | $pipeline = TvProcessingPipeline::createDefault(echoOutput: true); |
||
| 82 | $result = $pipeline->processRelease($release, $debug); |
||
| 83 | |||
| 84 | $this->newLine(); |
||
| 85 | |||
| 86 | if ($result['matched']) { |
||
| 87 | $this->colorCli->primary('Successfully matched!'); |
||
| 88 | $this->info('Provider: ' . ($result['provider'] ?? 'Unknown')); |
||
| 89 | $this->info('Video ID: ' . ($result['video_id'] ?? 'N/A')); |
||
| 90 | $this->info('Episode ID: ' . ($result['episode_id'] ?? 'N/A')); |
||
| 91 | } else { |
||
| 92 | $this->colorCli->warning('No match found.'); |
||
| 93 | $this->info('Status: ' . ($result['status'] ?? 'Unknown')); |
||
| 94 | if (isset($result['provider'])) { |
||
| 95 | $this->info('Last provider tried: ' . $result['provider']); |
||
| 96 | } |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($debug && isset($result['debug'])) { |
||
| 100 | $this->newLine(); |
||
| 101 | $this->info('Debug Information:'); |
||
| 102 | $this->line(json_encode($result['debug'], JSON_PRETTY_PRINT)); |
||
| 103 | } |
||
| 104 | |||
| 105 | // Show final state of the release |
||
| 106 | $release->refresh(); |
||
| 107 | $this->newLine(); |
||
| 108 | $this->info('Final release state:'); |
||
| 109 | $this->table( |
||
| 110 | ['Videos ID', 'Episode ID'], |
||
| 111 | [[$release->videos_id, $release->tv_episodes_id]] |
||
| 112 | ); |
||
| 113 | |||
| 114 | return self::SUCCESS; |
||
| 115 | } catch (\Throwable $e) { |
||
| 116 | Log::error($e->getTraceAsString()); |
||
| 117 | $this->error('Error processing release: ' . $e->getMessage()); |
||
| 118 | if ($debug) { |
||
| 119 | $this->error($e->getTraceAsString()); |
||
| 120 | } |
||
| 121 | return self::FAILURE; |
||
| 122 | } |
||
| 125 |
Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.