Conditions | 18 |
Paths | 30 |
Total Lines | 66 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | 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 |
||
37 | function admin_meta_matter_model($lang, $user, $accountIdOrName_unsafe, $playerIdOrName_unsafe, $points, $reason_unsafe, $confirmed) { |
||
38 | // If no points and no username - nothing to do |
||
39 | if (!$points && !$playerIdOrName_unsafe && !$accountIdOrName_unsafe) { |
||
40 | return; |
||
41 | } |
||
42 | |||
43 | if (!$points) { |
||
44 | throw new ExceptionSnLocalized('adm_mm_err_points_empty', ERR_ERROR); |
||
45 | } |
||
46 | |||
47 | $account = new Account(SN::$auth->account->db); |
||
48 | |||
49 | if (!empty($accountIdOrName_unsafe)) { |
||
50 | if ( |
||
51 | !$account->db_get_by_id($accountIdOrName_unsafe) |
||
52 | && |
||
53 | !$account->db_get_by_name($accountIdOrName_unsafe) |
||
54 | && |
||
55 | !$account->db_get_by_email($accountIdOrName_unsafe) |
||
56 | ) { |
||
57 | throw new ExceptionSnLocalized('adm_mm_err_account_not_found', ERR_ERROR); |
||
58 | } |
||
59 | } elseif (!empty($playerIdOrName_unsafe)) { |
||
60 | $row = dbPlayerByIdOrName($playerIdOrName_unsafe); |
||
|
|||
61 | if (empty($row['id'])) { |
||
62 | throw new ExceptionSnLocalized('adm_mm_err_player_not_found', ERR_ERROR, null, array($playerIdOrName_unsafe)); |
||
63 | } |
||
64 | |||
65 | if (!$account->dbGetByPlayerId($row['id'])) { |
||
66 | throw new ExceptionSnLocalized('adm_mm_err_player_no_account', ERR_ERROR, null, array($playerIdOrName_unsafe)); |
||
67 | } |
||
68 | } else { |
||
69 | throw new ExceptionSnLocalized('adm_mm_err_account_and_player_empty', ERR_ERROR); |
||
70 | } |
||
71 | |||
72 | $sprintfPayload = array( |
||
73 | $account->account_name, |
||
74 | $account->account_id, |
||
75 | HelperString::numberFloorAndFormat($points), |
||
76 | !empty($row['id']) ? $row['id'] : 0, |
||
77 | !empty($row['username']) ? $row['username'] : '' |
||
78 | ); |
||
79 | |||
80 | if ($confirmed) { |
||
81 | if (empty($account->metamatter_change( |
||
82 | RPG_ADMIN, |
||
83 | $points, |
||
84 | sprintf( |
||
85 | $lang['adm_mm_msg_change_mm_log_record'], |
||
86 | $account->account_id, |
||
87 | $account->account_name, |
||
88 | $user['id'], |
||
89 | $user['username'], |
||
90 | $reason_unsafe, |
||
91 | core_auth::$main_provider->account->account_id, |
||
92 | core_auth::$main_provider->account->account_name, |
||
93 | !empty($row['id']) ? $row['id'] : 0, |
||
94 | !empty($row['username']) ? $row['username'] : '' |
||
95 | ) |
||
96 | ))) { |
||
97 | throw new ExceptionSnLocalized($lang['adm_mm_err_mm_change_failed'], ERR_ERROR); |
||
98 | } |
||
99 | |||
100 | throw new ExceptionSnLocalized('adm_mm_msg_mm_changed', ERR_NONE, null, $sprintfPayload); |
||
101 | } else { |
||
102 | throw new ExceptionSnLocalized('adm_mm_msg_confirm_mm_change', ERR_WARNING, null, $sprintfPayload); |
||
103 | } |
||
152 |