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