Conditions | 11 |
Paths | 13 |
Total Lines | 30 |
Code Lines | 18 |
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 |
||
79 | private function combinePlayers() |
||
80 | { |
||
81 | if (count($this->players) < 4) { |
||
82 | throw new SecretSantaException("Not enough players to play, at least 4 players are required"); |
||
83 | } |
||
84 | |||
85 | $retry = count($this->players) + $this->players->countExcludePlayers(); |
||
86 | |||
87 | while (!$this->isValidCombination() && $retry > 0 ) { |
||
88 | $this->combination = []; |
||
89 | $secretPlayers = $this->players->shufflePlayers(); |
||
90 | foreach ($this->players as $playerId => $player) { |
||
91 | foreach ($secretPlayers as $secretPlayer) { |
||
92 | if ($player->id() != $secretPlayer->id() && !$this->players->areExclude($player, $secretPlayer)) { |
||
93 | if (!in_array($secretPlayer->id(), $this->combination)) { |
||
94 | $player->setSecretSanta($secretPlayer); |
||
95 | $this->combination[$player->id()] = $secretPlayer->id(); |
||
96 | unset ($secretPlayers[$secretPlayer->id()]); |
||
97 | break; |
||
98 | } |
||
99 | } |
||
100 | } |
||
101 | } |
||
102 | $retry--; |
||
103 | } |
||
104 | |||
105 | if (!$this->isValidCombination() && $retry <= 0) { |
||
106 | throw new SecretSantaException("Not enough players to play"); |
||
107 | } |
||
108 | } |
||
109 | |||
118 |