| Conditions | 10 |
| Paths | 2 |
| Total Lines | 17 |
| Code Lines | 13 |
| 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 |
||
| 33 | public function insertLostPosition(PlayerChartEvent $event): void |
||
| 34 | { |
||
| 35 | $playerChart = $event->getPlayerChart(); |
||
| 36 | $oldRank = $event->getOldRank(); |
||
| 37 | $oldNbEqual = $event->getOldNbEqual(); |
||
| 38 | $newRank = $playerChart->getRank(); |
||
| 39 | $newNbEqual = $playerChart->getNbEqual(); |
||
| 40 | |||
| 41 | if ((($oldRank >= 1) && ($oldRank <= 3) && ($newRank > $oldRank)) || |
||
| 42 | (($oldRank === 1) && ($oldNbEqual === 1) && ($newRank === 1) && ($newNbEqual > 1)) |
||
| 43 | ) { |
||
| 44 | $lostPosition = new LostPosition(); |
||
| 45 | $lostPosition->setNewRank($newRank); |
||
|
|
|||
| 46 | $lostPosition->setOldRank(($oldNbEqual == 1 && $oldRank == 1) ? 0 : $oldRank); //----- zero for losing platinum medal |
||
| 47 | $lostPosition->setPlayer($this->em->getReference(Player::class, $playerChart->getPlayer()->getId())); |
||
| 48 | $lostPosition->setChart($this->em->getReference(Chart::class, $playerChart->getChart()->getId())); |
||
| 49 | $this->em->persist($lostPosition); |
||
| 50 | } |
||
| 53 |