| Conditions | 13 | 
| Paths | 6 | 
| Total Lines | 51 | 
| Code Lines | 33 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| 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 | ||
| 35 | 	static function profile___patch () { | ||
| 36 | if ( | ||
| 37 | !isset($_POST['login'], $_POST['username'], $_POST['language'], $_POST['timezone'], $_POST['avatar']) || | ||
| 38 | !$_POST['login'] | ||
| 39 | 		) { | ||
| 40 | throw new ExitException(400); | ||
| 41 | } | ||
| 42 | $Config = Config::instance(); | ||
| 43 | $L = Language::instance(); | ||
| 44 | $User = User::instance(); | ||
| 45 | 		if ($User->guest()) { | ||
| 46 | throw new ExitException(403); | ||
| 47 | } | ||
| 48 | $user_data = [ | ||
| 49 | 'login' => $_POST['login'], | ||
| 50 | 'username' => $_POST['username'], | ||
| 51 | 'language' => $_POST['language'], | ||
| 52 | 'timezone' => $_POST['timezone'], | ||
| 53 | 'avatar' => $_POST['avatar'] | ||
| 54 | ]; | ||
| 55 | $user_data = xap($user_data, false); | ||
| 56 | if ( | ||
| 57 | ( | ||
| 58 | !in_array($user_data['timezone'], get_timezones_list()) && | ||
| 59 | $user_data['timezone'] !== '' | ||
| 60 | ) || | ||
| 61 | ( | ||
| 62 | !in_array($user_data['language'], $Config->core['active_languages']) && | ||
| 63 | $user_data['language'] !== '' | ||
| 64 | ) | ||
| 65 | 		) { | ||
| 66 | throw new ExitException(400); | ||
| 67 | } | ||
| 68 | $user_data['login'] = mb_strtolower($user_data['login']); | ||
| 69 | /** | ||
| 70 | * Check for changing login to new one and whether it is available | ||
| 71 | */ | ||
| 72 | if ( | ||
| 73 | $user_data['login'] != $User->login && | ||
| 74 | $user_data['login'] != $User->email && | ||
| 75 | ( | ||
| 76 | filter_var($user_data['login'], FILTER_VALIDATE_EMAIL) || | ||
| 77 | 				$User->get_id(hash('sha224', $user_data['login'])) !== false | ||
| 78 | ) | ||
| 79 | 		) { | ||
| 80 | throw new ExitException($L->login_occupied, 400); | ||
| 81 | } | ||
| 82 | 		if (!$User->set($user_data)) { | ||
| 83 | throw new ExitException(500); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | 	static function profile_contacts_get () { | ||
| 91 |