| Conditions | 12 |
| Paths | 11 |
| Total Lines | 81 |
| Code Lines | 51 |
| 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 |
||
| 31 | public function handle(): int |
||
| 32 | { |
||
| 33 | if ((int) Settings::settingValue('lookupxxx') !== 1) { |
||
| 34 | $this->error('Adult movie lookup is disabled in settings. Enable "lookupxxx" to use this command.'); |
||
| 35 | return Command::FAILURE; |
||
| 36 | } |
||
| 37 | |||
| 38 | $debug = $this->option('debug'); |
||
| 39 | $title = $this->option('title'); |
||
| 40 | $limit = $this->option('limit'); |
||
| 41 | |||
| 42 | $pipeline = new AdultProcessingPipeline([], true); |
||
| 43 | |||
| 44 | if ($title) { |
||
| 45 | // Process a single title |
||
| 46 | $this->info("Looking up: {$title}"); |
||
| 47 | |||
| 48 | $result = $pipeline->processMovie($title, $debug); |
||
|
|
|||
| 49 | |||
| 50 | if ($result['status'] === 'matched') { |
||
| 51 | $this->info("Match found on {$result['provider']}!"); |
||
| 52 | $title_display = $result['movieData']['title'] ?? 'N/A'; |
||
| 53 | $synopsis_display = substr($result['movieData']['synopsis'] ?? 'N/A', 0, 200); |
||
| 54 | $this->line("Title: {$title_display}"); |
||
| 55 | $this->line("Synopsis: {$synopsis_display}..."); |
||
| 56 | |||
| 57 | if (!empty($result['movieData']['boxcover'])) { |
||
| 58 | $cover_url = $result['movieData']['boxcover']; |
||
| 59 | $this->line("Cover: {$cover_url}"); |
||
| 60 | } |
||
| 61 | |||
| 62 | if ($debug && !empty($result['debug'])) { |
||
| 63 | $this->newLine(); |
||
| 64 | $this->line('Debug Info:'); |
||
| 65 | $this->line(json_encode($result['debug'], JSON_PRETTY_PRINT)); |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | $this->warn("No match found for: {$title}"); |
||
| 69 | |||
| 70 | if ($debug && !empty($result['debug'])) { |
||
| 71 | $this->newLine(); |
||
| 72 | $this->line('Debug Info:'); |
||
| 73 | $this->line(json_encode($result['debug'], JSON_PRETTY_PRINT)); |
||
| 74 | } |
||
| 75 | } |
||
| 76 | } else { |
||
| 77 | // Process all pending releases |
||
| 78 | $this->info('Processing adult movie releases using pipeline...'); |
||
| 79 | |||
| 80 | if ($limit) { |
||
| 81 | $this->info("Limited to {$limit} releases"); |
||
| 82 | } |
||
| 83 | |||
| 84 | $pipeline->processXXXReleases(); |
||
| 85 | |||
| 86 | $stats = $pipeline->getStats(); |
||
| 87 | |||
| 88 | $this->newLine(); |
||
| 89 | $this->table( |
||
| 90 | ['Metric', 'Value'], |
||
| 91 | [ |
||
| 92 | ['Processed', $stats['processed']], |
||
| 93 | ['Matched', $stats['matched']], |
||
| 94 | ['Failed', $stats['failed']], |
||
| 95 | ['Skipped', $stats['skipped']], |
||
| 96 | ['Duration', sprintf('%.2f seconds', $stats['duration'])], |
||
| 97 | ] |
||
| 98 | ); |
||
| 99 | |||
| 100 | if (!empty($stats['providers'])) { |
||
| 101 | $this->newLine(); |
||
| 102 | $this->info('Provider Statistics:'); |
||
| 103 | $providerData = []; |
||
| 104 | foreach ($stats['providers'] as $provider => $count) { |
||
| 105 | $providerData[] = [$provider, $count]; |
||
| 106 | } |
||
| 107 | $this->table(['Provider', 'Matches'], $providerData); |
||
| 108 | } |
||
| 109 | } |
||
| 110 | |||
| 111 | return Command::SUCCESS; |
||
| 112 | } |
||
| 115 |