| Conditions | 17 | 
| Paths | 2256 | 
| Total Lines | 135 | 
| Code Lines | 90 | 
| 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 | ||
| 67 | protected function execute(InputInterface $input, OutputInterface $output): int | ||
| 68 |     { | ||
| 69 | $io = new SymfonyStyle($input, $output); | ||
| 70 |         $dryRun = $input->getOption('dry-run'); | ||
| 71 |         $gameIds = $input->getOption('game-id'); | ||
| 72 |         $limit = (int) $input->getOption('limit'); | ||
| 73 |         $batchSize = (int) $input->getOption('batch-size'); | ||
| 74 |         $withoutIgdbOnly = $input->getOption('without-igdb-only'); | ||
| 75 | |||
| 76 |         $io->title('IGDB Game Matching Service'); | ||
| 77 | |||
| 78 |         if ($dryRun) { | ||
| 79 |             $io->note('Running in DRY-RUN mode - no changes will be made to the database'); | ||
| 80 | } | ||
| 81 | |||
| 82 |         try { | ||
| 83 | $games = $this->getGamesToProcess($gameIds, $withoutIgdbOnly, $limit); | ||
| 84 | $totalGames = count($games); | ||
| 85 | |||
| 86 |             if ($totalGames === 0) { | ||
| 87 |                 $io->success('No games to process.'); | ||
| 88 | return Command::SUCCESS; | ||
| 89 | } | ||
| 90 | |||
| 91 |             $io->info(sprintf('Found %d games to process', $totalGames)); | ||
| 92 | |||
| 93 |             if (!$dryRun) { | ||
| 94 | $statistics = $this->gameMatchingService->getMatchingStatistics(); | ||
| 95 |                 $io->section('Current Statistics'); | ||
| 96 | $io->table( | ||
| 97 | ['Metric', 'Value'], | ||
| 98 | [ | ||
| 99 | ['Total Games', $statistics['total_games']], | ||
| 100 | ['Games with IGDB Association', $statistics['games_with_igdb_association']], | ||
| 101 | ['Games without IGDB Association', $statistics['games_without_igdb_association']], | ||
| 102 | ['Matching Percentage', $statistics['matching_percentage'] . '%'] | ||
| 103 | ] | ||
| 104 | ); | ||
| 105 | } | ||
| 106 | |||
| 107 | $io->progressStart($totalGames); | ||
| 108 | |||
| 109 | $processedCount = 0; | ||
| 110 | $matchedCount = 0; | ||
| 111 | $errorCount = 0; | ||
| 112 | $skippedCount = 0; | ||
| 113 | |||
| 114 |             foreach (array_chunk($games, $batchSize) as $gameBatch) { | ||
| 115 |                 foreach ($gameBatch as $game) { | ||
| 116 |                     try { | ||
| 117 |                         if ($game->getIgdbGame() !== null && $withoutIgdbOnly) { | ||
| 118 | $skippedCount++; | ||
| 119 | $io->progressAdvance(); | ||
| 120 | continue; | ||
| 121 | } | ||
| 122 | |||
| 123 |                         if ($dryRun) { | ||
| 124 | $io->text(sprintf( | ||
| 125 | 'Would process: %s (ID: %d) - Platforms: %s', | ||
| 126 | $game->getLibGameEn(), | ||
| 127 | $game->getId(), | ||
| 128 | $this->getPlatformNames($game) | ||
| 129 | )); | ||
| 130 | $processedCount++; | ||
| 131 |                         } else { | ||
| 132 | $igdbGame = $this->gameMatchingService->findAndAssociateIgdbGame($game); | ||
| 133 | |||
| 134 |                             if ($igdbGame !== null) { | ||
| 135 | $matchedCount++; | ||
| 136 | $io->text(sprintf( | ||
| 137 | 'Matched: %s → IGDB Game ID: %d', | ||
| 138 | $game->getLibGameEn(), | ||
| 139 | $igdbGame->getId() | ||
| 140 | )); | ||
| 141 | } | ||
| 142 | $processedCount++; | ||
| 143 | } | ||
| 144 |                     } catch (\Exception $e) { | ||
| 145 | $errorCount++; | ||
| 146 | $io->error(sprintf( | ||
| 147 | 'Error processing game %s (ID: %d): %s', | ||
| 148 | $game->getLibGameEn(), | ||
| 149 | $game->getId(), | ||
| 150 | $e->getMessage() | ||
| 151 | )); | ||
| 152 | } | ||
| 153 | |||
| 154 | $io->progressAdvance(); | ||
| 155 | } | ||
| 156 | |||
| 157 |                 if (!$dryRun) { | ||
| 158 | $this->entityManager->clear(); | ||
| 159 | } | ||
| 160 | } | ||
| 161 | |||
| 162 | $io->progressFinish(); | ||
| 163 | |||
| 164 |             $io->section('Processing Summary'); | ||
| 165 | $resultTable = [ | ||
| 166 | ['Total Games Processed', $processedCount], | ||
| 167 | ['Successfully Matched', $matchedCount], | ||
| 168 | ['Errors', $errorCount], | ||
| 169 | ['Skipped (already matched)', $skippedCount] | ||
| 170 | ]; | ||
| 171 | |||
| 172 |             if ($dryRun) { | ||
| 173 | $resultTable[] = ['⚠️ DRY RUN MODE', 'No changes made']; | ||
| 174 | } | ||
| 175 | |||
| 176 | $io->table(['Metric', 'Count'], $resultTable); | ||
| 177 | |||
| 178 |             if (!$dryRun && $matchedCount > 0) { | ||
| 179 |                 $io->section('Updated Statistics'); | ||
| 180 | $finalStatistics = $this->gameMatchingService->getMatchingStatistics(); | ||
| 181 | $io->table( | ||
| 182 | ['Metric', 'Value'], | ||
| 183 | [ | ||
| 184 | ['Total Games', $finalStatistics['total_games']], | ||
| 185 | ['Games with IGDB Association', $finalStatistics['games_with_igdb_association']], | ||
| 186 | ['Games without IGDB Association', $finalStatistics['games_without_igdb_association']], | ||
| 187 | ['Matching Percentage', $finalStatistics['matching_percentage'] . '%'] | ||
| 188 | ] | ||
| 189 | ); | ||
| 190 | } | ||
| 191 | |||
| 192 |             if ($errorCount > 0) { | ||
| 193 |                 $io->warning(sprintf('%d errors occurred during processing. Check the logs for details.', $errorCount)); | ||
| 194 | return Command::FAILURE; | ||
| 195 | } | ||
| 196 | |||
| 197 |             $io->success('Game matching completed successfully!'); | ||
| 198 | return Command::SUCCESS; | ||
| 199 |         } catch (\Exception $e) { | ||
| 200 |             $io->error('Command failed: ' . $e->getMessage()); | ||
| 201 | return Command::FAILURE; | ||
| 202 | } | ||
| 232 |