| Conditions | 4 |
| Paths | 39 |
| Total Lines | 61 |
| Code Lines | 45 |
| 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 |
||
| 29 | protected function execute(InputInterface $input, OutputInterface $output): int |
||
| 30 | { |
||
| 31 | $io = new SymfonyStyle($input, $output); |
||
| 32 | |||
| 33 | $io->title('Importing platform logos from IGDB API'); |
||
| 34 | |||
| 35 | try { |
||
| 36 | $platformLogos = $this->igdbClient->getAllPlatformLogos(); |
||
| 37 | $io->progressStart(count($platformLogos)); |
||
| 38 | |||
| 39 | $insertedCount = 0; |
||
| 40 | $updatedCount = 0; |
||
| 41 | |||
| 42 | foreach ($platformLogos as $platformLogoData) { |
||
| 43 | $existingPlatformLogo = $this->entityManager |
||
| 44 | ->getRepository(PlatformLogo::class) |
||
| 45 | ->find($platformLogoData['id']); |
||
| 46 | |||
| 47 | if ($existingPlatformLogo) { |
||
| 48 | // Pas de timestamps dans l'API, on met toujours à jour |
||
| 49 | $existingPlatformLogo->setAlphaChannel($platformLogoData['alpha_channel'] ?? false); |
||
| 50 | $existingPlatformLogo->setAnimated($platformLogoData['animated'] ?? false); |
||
| 51 | $existingPlatformLogo->setChecksum($platformLogoData['checksum'] ?? null); |
||
| 52 | $existingPlatformLogo->setHeight($platformLogoData['height'] ?? 0); |
||
| 53 | $existingPlatformLogo->setImageId($platformLogoData['image_id'] ?? ''); |
||
| 54 | $existingPlatformLogo->setUrl($platformLogoData['url'] ?? null); |
||
| 55 | $existingPlatformLogo->setWidth($platformLogoData['width'] ?? 0); |
||
| 56 | $existingPlatformLogo->setUpdatedAt(new \DateTimeImmutable()); |
||
| 57 | $updatedCount++; |
||
| 58 | } else { |
||
| 59 | $platformLogo = new PlatformLogo(); |
||
| 60 | $platformLogo->setId($platformLogoData['id']); |
||
| 61 | $platformLogo->setAlphaChannel($platformLogoData['alpha_channel'] ?? false); |
||
| 62 | $platformLogo->setAnimated($platformLogoData['animated'] ?? false); |
||
| 63 | $platformLogo->setChecksum($platformLogoData['checksum'] ?? null); |
||
| 64 | $platformLogo->setHeight($platformLogoData['height'] ?? 0); |
||
| 65 | $platformLogo->setImageId($platformLogoData['image_id'] ?? ''); |
||
| 66 | $platformLogo->setUrl($platformLogoData['url'] ?? null); |
||
| 67 | $platformLogo->setWidth($platformLogoData['width'] ?? 0); |
||
| 68 | |||
| 69 | $this->entityManager->persist($platformLogo); |
||
| 70 | $insertedCount++; |
||
| 71 | } |
||
| 72 | |||
| 73 | $io->progressAdvance(); |
||
| 74 | } |
||
| 75 | |||
| 76 | $this->entityManager->flush(); |
||
| 77 | $io->progressFinish(); |
||
| 78 | |||
| 79 | $io->success([ |
||
| 80 | "Platform logos imported successfully!", |
||
| 81 | "Inserted: $insertedCount platform logos", |
||
| 82 | "Updated: $updatedCount platform logos", |
||
| 83 | "Total processed: " . ($insertedCount + $updatedCount) . " platform logos" |
||
| 84 | ]); |
||
| 85 | |||
| 86 | return Command::SUCCESS; |
||
| 87 | } catch (\Exception $e) { |
||
| 88 | $io->error('Failed to import platform logos: ' . $e->getMessage()); |
||
| 89 | return Command::FAILURE; |
||
| 90 | } |
||
| 93 |