Conditions | 15 |
Paths | 3078 |
Total Lines | 123 |
Code Lines | 76 |
Lines | 18 |
Ratio | 14.63 % |
Changes | 7 | ||
Bugs | 1 | 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 namespace GolfLeague\Services; |
||
56 | public function create($matchdata) |
||
57 | { |
||
58 | $this->prizeMoney->setPurse($matchdata['purse']); |
||
59 | |||
60 | $matchdata['purse'] = number_format($matchdata['purse'], 2); |
||
61 | $matchdata['grossmoney'] = $this->prizeMoney->getlowScore(); |
||
62 | $matchdata['netmoney'] = $this->prizeMoney->getlowScore(); |
||
63 | |||
64 | //How many A and B players |
||
65 | $totalPlayers = 0; |
||
66 | |||
67 | $aPlayerCount = 0; |
||
68 | |||
69 | $bPlayerCount = 0; |
||
70 | foreach($matchdata['player'] as $player){ |
||
71 | if ($player['level_id'] == '1'){ |
||
72 | $aPlayerCount++; |
||
73 | } |
||
74 | else { |
||
75 | $bPlayerCount++; |
||
76 | } |
||
77 | $totalPlayers++; |
||
78 | } |
||
79 | |||
80 | //Calculate Skins money based on how many players in each group |
||
81 | |||
82 | $matchdata['skinsamoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $aPlayerCount); |
||
83 | $matchdata['skinsbmoney'] = $this->prizeMoney->skinsGroupPot($matchdata['purse'], $totalPlayers, $bPlayerCount); |
||
84 | //check for carry over money and if there is add it to skins money |
||
85 | $carryOver = new CarryOver; |
||
86 | $carryOverMoney = $carryOver->calculate(); |
||
87 | $matchdata['skinsamoney'] += $carryOverMoney[1]; |
||
88 | $matchdata['skinsbmoney'] += $carryOverMoney[2]; |
||
89 | |||
90 | //append current handicap and set winnings to 0 for each player |
||
91 | foreach ($matchdata['player'] as $key=>$player) { |
||
92 | //get each player's current handicap |
||
93 | $currentPlayer = $this->player->find($player['player_id']); |
||
94 | $matchdata['player'][$key]['handicap'] = $currentPlayer->handicap; |
||
95 | $matchdata['player'][$key]['winnings'] = 0; |
||
96 | }// End foreach |
||
97 | |||
98 | $matchid = $this->matchRepo->create($matchdata); |
||
99 | $matchdata['match_id'] = $matchid; |
||
100 | $this->events->fire('match.create', array($matchdata)); // MatchHandler and teamMatchHandler are listening... |
||
101 | |||
102 | // Run for team Matches |
||
103 | if($matchdata['matchType'] === 'team' || $matchdata['matchType'] === 'both'){ |
||
104 | |||
105 | foreach ($matchdata['teamMatchUp1'] as $teamKey => $team){ |
||
106 | $matchUp1[] = $this->search($matchdata['player'], 'team', $team); |
||
107 | } |
||
108 | |||
109 | //Save matchUp 1 |
||
110 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
111 | $match1['team_id'] = $matchUp1[0][0]['team']; |
||
112 | $match1['player1'] = $matchUp1[0][0]['player_id']; |
||
113 | View Code Duplication | if(isset($matchUp1[0][1]['player_id'])){ |
|
114 | $match1['player2'] = $matchUp1[0][1]['player_id']; |
||
115 | } |
||
116 | $match1['opponent'] = $matchUp1[1][0]['team']; |
||
117 | $this->teammatch->create($match1); //save to match table |
||
118 | |||
119 | $match1['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
120 | $match1['team_id'] = $matchUp1[1][0]['team']; |
||
121 | $match1['player1'] = $matchUp1[1][0]['player_id']; |
||
122 | View Code Duplication | if(isset($matchUp1[1][1]['player_id'])){ |
|
123 | $match1['player2'] = $matchUp1[1][1]['player_id']; |
||
124 | } |
||
125 | $match1['opponent'] = $matchUp1[0][0]['team']; |
||
126 | $this->teammatch->create($match1); //save to match table |
||
127 | |||
128 | |||
129 | foreach ($matchdata['teamMatchUp2'] as $teamKey => $team){ |
||
130 | $matchUp2[] = $this->search($matchdata['player'], 'team', $team); |
||
131 | } |
||
132 | |||
133 | //Save matchUp 2 |
||
134 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
135 | $match2['team_id'] = $matchUp2[0][0]['team']; |
||
136 | $match2['player1'] = $matchUp2[0][0]['player_id']; |
||
137 | View Code Duplication | if(isset($matchUp2[0][1]['player_id'])){ |
|
138 | $match2['player2'] = $matchUp2[0][1]['player_id']; |
||
139 | } |
||
140 | $match2['opponent'] = $matchUp2[1][0]['team']; |
||
141 | $this->teammatch->create($match2); //save to match table |
||
142 | |||
143 | $match2['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
144 | $match2['team_id'] = $matchUp2[1][0]['team']; |
||
145 | $match2['player1'] = $matchUp2[1][0]['player_id']; |
||
146 | View Code Duplication | if(isset($matchUp2[1][1]['player_id'])){ |
|
147 | $match2['player2'] = $matchUp2[1][1]['player_id']; |
||
148 | } |
||
149 | $match2['opponent'] = $matchUp2[0][0]['team']; |
||
150 | $this->teammatch->create($match2); //save to match table |
||
151 | |||
152 | |||
153 | foreach ($matchdata['teamMatchUp3'] as $teamKey => $team){ |
||
154 | $matchUp3[] = $this->search($matchdata['player'], 'team', $team); |
||
155 | } |
||
156 | |||
157 | //Save matchUp 3 |
||
158 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
159 | $match3['team_id'] = $matchUp3[0][0]['team']; |
||
160 | $match3['player1'] = $matchUp3[0][0]['player_id']; |
||
161 | View Code Duplication | if(isset($matchUp3[0][1]['player_id'])){ |
|
162 | $match3['player2'] = $matchUp3[0][1]['player_id']; |
||
163 | } |
||
164 | |||
165 | $match3['opponent'] = $matchUp3[1][0]['team']; |
||
166 | $this->teammatch->create($match3); //save to match table |
||
167 | |||
168 | $match3['match_id'] = $matchdata['match_id']; // This is generated below and passed to listener |
||
169 | $match3['team_id'] = $matchUp3[1][0]['team']; |
||
170 | $match3['player1'] = $matchUp3[1][0]['player_id']; |
||
171 | View Code Duplication | if(isset($matchUp3[1][1]['player_id'])){ |
|
172 | $match3['player2'] = $matchUp3[1][1]['player_id']; |
||
173 | } |
||
174 | $match3['opponent'] = $matchUp3[0][0]['team']; |
||
175 | $this->teammatch->create($match3); //save to match table |
||
176 | |||
177 | } |
||
178 | } |
||
179 | |||
386 |
Adding a
@return
annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.Please refer to the PHP core documentation on constructors.