| Conditions | 12 |
| Paths | 16 |
| Total Lines | 42 |
| Code Lines | 26 |
| 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 |
||
| 96 | private function updateGame(Game $game, array $gameData): void |
||
| 97 | { |
||
| 98 | $game->setName($gameData['name']); |
||
| 99 | $game->setSlug($gameData['slug'] ?? null); |
||
| 100 | $game->setStoryline($gameData['storyline'] ?? null); |
||
| 101 | $game->setSummary($gameData['summary'] ?? null); |
||
| 102 | $game->setUrl($gameData['url'] ?? null); |
||
| 103 | $game->setChecksum($gameData['checksum'] ?? null); |
||
| 104 | $game->setFirstReleaseDate($gameData['first_release_date'] ?? null); |
||
| 105 | |||
| 106 | // Gérer l'association avec version_parent (auto-référence) |
||
| 107 | if (isset($gameData['version_parent']) && is_numeric($gameData['version_parent'])) { |
||
| 108 | $versionParent = $this->entityManager->getRepository(Game::class)->find($gameData['version_parent']); |
||
| 109 | $game->setVersionParent($versionParent); |
||
| 110 | } |
||
| 111 | |||
| 112 | // Gérer les associations ManyToMany avec les genres |
||
| 113 | $game->getGenres()->clear(); |
||
| 114 | if (isset($gameData['genres']) && is_array($gameData['genres'])) { |
||
| 115 | foreach ($gameData['genres'] as $genreId) { |
||
| 116 | $genre = $this->entityManager->getRepository(Genre::class)->find($genreId); |
||
| 117 | if ($genre) { |
||
| 118 | $game->addGenre($genre); |
||
| 119 | } |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | // Gérer les associations ManyToMany avec les plateformes |
||
| 124 | $game->getPlatforms()->clear(); |
||
| 125 | if (isset($gameData['platforms']) && is_array($gameData['platforms'])) { |
||
| 126 | foreach ($gameData['platforms'] as $platformId) { |
||
| 127 | $platform = $this->entityManager->getRepository(Platform::class)->find($platformId); |
||
| 128 | if ($platform) { |
||
| 129 | $game->addPlatform($platform); |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | if (isset($gameData['updated_at'])) { |
||
| 135 | $game->setUpdatedAt(new \DateTimeImmutable('@' . $gameData['updated_at'])); |
||
| 136 | } else { |
||
| 137 | $game->setUpdatedAt(new \DateTimeImmutable()); |
||
| 138 | } |
||
| 141 |