| Conditions | 12 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 113 | public static function validators() |
||
| 114 | { |
||
| 115 | return [ |
||
| 116 | 'userSearch' => function($activeForm, $request) { |
||
| 117 | if (empty($request['userSearch'])) { |
||
| 118 | throw new \Exception('Не указан получатель'); |
||
| 119 | } |
||
| 120 | if (!((int) $request['userSearch'])) { |
||
| 121 | throw new \Exception('Не указан получатель'); |
||
| 122 | } |
||
| 123 | $user = \Users\User::get((int) $request['userSearch']); |
||
| 124 | if (!$user) { |
||
| 125 | throw new \Exception('Такой пользователь не найден'); |
||
| 126 | } |
||
| 127 | if ($user->id == \Users\User::$cur->id) { |
||
| 128 | throw new \Exception('Нельзя выбрать себя в качестве получателя'); |
||
| 129 | } |
||
| 130 | return true; |
||
| 131 | }, |
||
| 132 | 'amount' => function($activeForm, $request) { |
||
| 133 | if (empty($request['amount'])) { |
||
| 134 | throw new \Exception('Не указана сумма'); |
||
| 135 | } |
||
| 136 | if (!((float) $request['amount'])) { |
||
| 137 | throw new \Exception('Не указана сумма'); |
||
| 138 | } |
||
| 139 | $amount = (float) $request['amount']; |
||
| 140 | if (empty($request['wallets'])) { |
||
| 141 | throw new \Exception('Не указан кошелек'); |
||
| 142 | } |
||
| 143 | if (!((int) $request['wallets'])) { |
||
| 144 | throw new \Exception('Не указан кошелек'); |
||
| 145 | } |
||
| 146 | $wallets = \App::$cur->money->getUserWallets(); |
||
| 147 | if (empty($wallets[(int) $request['wallets']])) { |
||
| 148 | throw new \Exception('У вас нет такого кошелька'); |
||
| 149 | } |
||
| 150 | $wallet = $wallets[(int) $request['wallets']]; |
||
| 151 | if (!$wallet->currency->transfer) { |
||
| 152 | throw new \Exception('Вы не можете переводить эту валюту'); |
||
| 153 | } |
||
| 154 | if ($wallet->amount < $amount) { |
||
| 155 | throw new \Exception('У вас недостаточно средств на кошельке'); |
||
| 156 | } |
||
| 157 | return true; |
||
| 158 | }, |
||
| 159 | 'commentClean' => function($activeForm, &$request) { |
||
| 160 | $request['comment'] = trim(htmlspecialchars(urldecode($request['comment']))); |
||
| 161 | } |
||
| 162 | ]; |
||
| 163 | } |
||
| 164 | |||
| 227 |