| Conditions | 22 |
| Paths | 5120 |
| Total Lines | 84 |
| Code Lines | 56 |
| 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 |
||
| 133 | function player_create($username_unsafe, $email_unsafe, $options) { |
||
| 134 | db_mysql::db_transaction_check(true); |
||
| 135 | |||
| 136 | static $player_options_string = 'opt_mnl_spy^1|opt_email_mnl_spy^0|opt_email_mnl_joueur^0|opt_email_mnl_alliance^0|opt_mnl_attaque^1|opt_email_mnl_attaque^0|opt_mnl_exploit^1|opt_email_mnl_exploit^0|opt_mnl_transport^1|opt_email_mnl_transport^0|opt_email_msg_admin^1|opt_mnl_expedition^1|opt_email_mnl_expedition^0|opt_mnl_buildlist^1|opt_email_mnl_buildlist^0|opt_int_navbar_resource_force^1|'; |
||
| 137 | |||
| 138 | empty($options['planet_options']) ? $options['planet_options'] = [] : false; |
||
| 139 | |||
| 140 | $field_set = array( |
||
| 141 | 'server_name' => SN_ROOT_VIRTUAL, |
||
| 142 | 'register_time' => SN_TIME_NOW, |
||
| 143 | 'news_lastread' => SN_TIME_NOW, |
||
| 144 | 'user_bot' => $options['user_bot'] = empty($options['user_bot']) ? USER_BOT_PLAYER : $options['user_bot'], |
||
| 145 | |||
| 146 | 'username' => $username_unsafe, |
||
| 147 | 'email' => $email_unsafe, |
||
| 148 | 'email_2' => $email_unsafe, |
||
| 149 | |||
| 150 | 'lang' => $options['language_iso'] ? $options['language_iso'] : DEFAULT_LANG, |
||
| 151 | 'skin' => DEFAULT_SKIN_NAME, |
||
| 152 | |||
| 153 | 'total_points' => $options['total_points'] = empty($options['total_points']) ? 0 : $options['total_points'], |
||
| 154 | |||
| 155 | 'options' => (empty($options['options']) ? $player_options_string : $options['options']) . (empty($options['options_extra']) ? '' : $options['options_extra']), |
||
| 156 | |||
| 157 | 'galaxy' => $options['galaxy'] = intval($options['galaxy'] ? $options['galaxy'] : 0), |
||
| 158 | 'system' => $options['system'] = intval($options['system'] ? $options['system'] : 0), |
||
| 159 | 'planet' => $options['planet'] = intval($options['planet'] ? $options['planet'] : 0), |
||
| 160 | ); |
||
| 161 | |||
| 162 | !empty($options['salt']) ? $field_set['salt'] = $options['salt'] : false; |
||
| 163 | !empty($options['password_encoded_unsafe']) ? $field_set['password'] = $options['password_encoded_unsafe'] : false; |
||
| 164 | \DBAL\DbQuery::build()->setTable('users')->setValues($field_set)->doInsert(); |
||
| 165 | $user_new = db_user_by_id(SN::$db->db_insert_id()); |
||
| 166 | |||
| 167 | if (!($options['galaxy'] && $options['system'] && $options['planet'])) { |
||
| 168 | $options['galaxy'] = SN::$config->LastSettedGalaxyPos; |
||
| 169 | $options['system'] = SN::$config->LastSettedSystemPos; |
||
| 170 | $segment_size = floor(SN::$config->game_maxPlanet / 3); |
||
| 171 | $segment = floor(SN::$config->LastSettedPlanetPos / $segment_size); |
||
| 172 | $segment++; |
||
| 173 | $options['planet'] = mt_rand(1 + $segment * $segment_size, ($segment + 1) * $segment_size); |
||
| 174 | |||
| 175 | while (true) { |
||
| 176 | if ($options['planet'] > SN::$config->game_maxPlanet) { |
||
| 177 | $options['planet'] = mt_rand(0, $segment_size - 1) + 1; |
||
| 178 | $options['system']++; |
||
| 179 | } |
||
| 180 | if ($options['system'] > SN::$config->game_maxSystem) { |
||
| 181 | $options['system'] = 1; |
||
| 182 | $options['galaxy']++; |
||
| 183 | } |
||
| 184 | $options['galaxy'] > SN::$config->game_maxGalaxy ? $options['galaxy'] = 1 : false; |
||
| 185 | |||
| 186 | $galaxy_row = DBStaticPlanet::db_planet_by_gspt($options['galaxy'], $options['system'], $options['planet'], PT_PLANET); |
||
| 187 | if (!$galaxy_row['id']) { |
||
| 188 | SN::$config->db_saveItem(array( |
||
| 189 | 'LastSettedGalaxyPos' => $options['galaxy'], |
||
| 190 | 'LastSettedSystemPos' => $options['system'], |
||
| 191 | 'LastSettedPlanetPos' => $options['planet'], |
||
| 192 | )); |
||
| 193 | break; |
||
| 194 | } |
||
| 195 | $options['planet'] += 3; |
||
| 196 | } |
||
| 197 | } |
||
| 198 | $new_planet_id = uni_create_planet($options['galaxy'], $options['system'], $options['planet'], $user_new['id'], '', true, $options['planet_options']); |
||
| 199 | |||
| 200 | db_user_set_by_id($user_new['id'], |
||
| 201 | "`id_planet` = '{$new_planet_id}', `current_planet` = '{$new_planet_id}', |
||
| 202 | `galaxy` = '{$options['galaxy']}', `system` = '{$options['system']}', `planet` = '{$options['planet']}'" |
||
| 203 | ); |
||
| 204 | |||
| 205 | $username_safe = SN::$db->db_escape($username_unsafe); |
||
| 206 | doquery("REPLACE INTO `{{player_name_history}}` SET `player_id` = {$user_new['id']}, `player_name` = '{$username_safe}'"); |
||
| 207 | |||
| 208 | if (!empty($options['partner_id']) && ($referral_row = db_user_by_id($options['partner_id'], true))) { |
||
| 209 | doquery("INSERT INTO `{{referrals}}` SET `id` = {$user_new['id']}, `id_partner` = {$options['partner_id']}"); |
||
| 210 | } |
||
| 211 | |||
| 212 | sys_player_new_adjust($user_new['id'], $new_planet_id); |
||
| 213 | |||
| 214 | dbUpdateUsersCount(SN::$config->pass()->users_amount + 1); |
||
| 215 | |||
| 216 | return $result = db_user_by_id($user_new['id']); |
||
| 217 | } |
||
| 218 |