| Conditions | 8 |
| Paths | 16 |
| Total Lines | 64 |
| Code Lines | 38 |
| 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 findAndAssociateIgdbGame(Game $coreGame): ?IgdbGame |
||
| 26 | { |
||
| 27 | if ($coreGame->getIgdbGame() !== null) { |
||
| 28 | $this->logger->info('Game already has IGDB association', ['gameId' => $coreGame->getId()]); |
||
| 29 | return $coreGame->getIgdbGame(); |
||
| 30 | } |
||
| 31 | |||
| 32 | $gameName = $coreGame->getLibGameEn(); |
||
| 33 | $this->logger->info('Searching IGDB game for: ' . $gameName, ['gameId' => $coreGame->getId()]); |
||
| 34 | |||
| 35 | $corePlatforms = $coreGame->getPlatforms(); |
||
| 36 | $igdbPlatformIds = []; |
||
| 37 | |||
| 38 | foreach ($corePlatforms as $corePlatform) { |
||
| 39 | $igdbPlatformId = $this->igdbMappingService->getPlatformIgdbId($corePlatform->getId()); |
||
| 40 | if ($igdbPlatformId !== null) { |
||
| 41 | $igdbPlatformIds[] = $igdbPlatformId; |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | if (empty($igdbPlatformIds)) { |
||
| 46 | $this->logger->warning('No IGDB platform mappings found for game', [ |
||
| 47 | 'gameId' => $coreGame->getId(), |
||
| 48 | 'gameName' => $gameName |
||
| 49 | ]); |
||
| 50 | return null; |
||
| 51 | } |
||
| 52 | |||
| 53 | $this->logger->info('Using IGDB platform IDs for search', [ |
||
| 54 | 'gameId' => $coreGame->getId(), |
||
| 55 | 'igdbPlatformIds' => $igdbPlatformIds |
||
| 56 | ]); |
||
| 57 | |||
| 58 | $igdbGames = $this->igdbClient->searchGamesByName($gameName, $igdbPlatformIds, 50); |
||
| 59 | |||
| 60 | foreach ($igdbGames as $igdbGameData) { |
||
| 61 | if ($this->isExactMatch($coreGame, $igdbGameData)) { |
||
| 62 | $igdbGame = $this->findOrCreateIgdbGame($igdbGameData); |
||
| 63 | |||
| 64 | if ($igdbGame !== null) { |
||
| 65 | $coreGame->setIgdbGame($igdbGame); |
||
| 66 | $this->igdbMappingService->setGameMapping($coreGame->getId(), $igdbGame->getId()); |
||
|
|
|||
| 67 | |||
| 68 | $this->entityManager->persist($coreGame); |
||
| 69 | $this->entityManager->flush(); |
||
| 70 | |||
| 71 | $this->logger->info('Successfully associated IGDB game', [ |
||
| 72 | 'coreGameId' => $coreGame->getId(), |
||
| 73 | 'igdbGameId' => $igdbGame->getId(), |
||
| 74 | 'gameName' => $gameName |
||
| 75 | ]); |
||
| 76 | |||
| 77 | return $igdbGame; |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | $this->logger->info('No exact match found in IGDB', [ |
||
| 83 | 'gameId' => $coreGame->getId(), |
||
| 84 | 'gameName' => $gameName, |
||
| 85 | 'searchResults' => count($igdbGames) |
||
| 86 | ]); |
||
| 87 | |||
| 88 | return null; |
||
| 89 | } |
||
| 193 |