Conditions | 26 |
Paths | 206 |
Total Lines | 71 |
Code Lines | 53 |
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 |
||
167 | public function reward($reward_id, $sums = [], $rootUser = null) { |
||
168 | $rootUser = $rootUser ? $rootUser : \Users\User::$cur; |
||
169 | $reward = \Money\Reward::get($reward_id); |
||
170 | if (!$reward->active) { |
||
171 | return false; |
||
172 | } |
||
173 | $reward->checkBlocked(); |
||
174 | $reward_count = \Money\Reward\Recive::getCount(['where' => ['reward_id', $reward_id]]); |
||
175 | if ($reward_count >= $reward->quantity && $reward->quantity) { |
||
176 | return false; |
||
177 | } |
||
178 | $types = $this->getSnippets('rewardType'); |
||
179 | $checkers = $this->getSnippets('userActivity'); |
||
180 | foreach ($reward->levels(['order' => ['level', 'asc']]) as $level) { |
||
181 | $user = $rootUser; |
||
182 | for ($i = 0; $i < $level->level; $i++) { |
||
183 | $next = $user && $user->parent ? $user->parent : false; |
||
184 | if (!$next && $reward->lasthaveall) { |
||
185 | break; |
||
186 | } |
||
187 | $noActive = $next->blocked; |
||
188 | foreach ($checkers as $checker) { |
||
189 | if ($noActive) { |
||
190 | break; |
||
191 | } |
||
192 | $noActive = !$checker['checker']($next); |
||
193 | } |
||
194 | if ($next && $next->parent_id && $noActive) { |
||
195 | foreach ($next->users as $childUser) { |
||
196 | $childUser->parent_id = $next->parent_id; |
||
197 | $childUser->save(); |
||
198 | } |
||
199 | $i--; |
||
200 | $user = Users\User::get($user->id); |
||
201 | $rootUser = Users\User::get($rootUser->id); |
||
202 | continue; |
||
203 | } |
||
204 | $user = $next; |
||
205 | } |
||
206 | if (!$user) { |
||
207 | continue; |
||
208 | } |
||
209 | |||
210 | if ($reward->peruser) { |
||
211 | $recives = \Money\Reward\Recive::getList(['where' => [['user_id', $user->id], ['reward_id', $reward->id]]]); |
||
212 | $amount = 0; |
||
213 | foreach ($recives as $recive) { |
||
214 | $amount += $recive->amount; |
||
215 | } |
||
216 | if ($amount >= $reward->peruser) { |
||
217 | continue; |
||
218 | } |
||
219 | } |
||
220 | $rewardGet = true; |
||
221 | if (!$level->nocondition) { |
||
222 | foreach ($reward->conditions as $condition) { |
||
223 | if (!$condition->checkComplete($user->id)) { |
||
224 | $rewardGet = false; |
||
225 | break; |
||
226 | } |
||
227 | } |
||
228 | if (!$rewardGet && !$reward->block) { |
||
229 | continue; |
||
230 | } |
||
231 | } |
||
232 | $recive = new \Money\Reward\Recive(); |
||
233 | $recive->reward_id = $reward->id; |
||
234 | $recive->user_id = $user->id; |
||
235 | $recive->amount = 1; |
||
236 | $recive->save(); |
||
237 | return $types[$level->type]['rewarder']($reward, $sums, $user, $rootUser, $level, $rewardGet); |
||
238 | } |
||
240 | } |