| Conditions | 2 |
| Paths | 2 |
| Total Lines | 54 |
| Code Lines | 51 |
| 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 |
||
| 39 | function make_user($user) { |
||
| 40 | $prefs = $user->global_prefs; |
||
| 41 | |||
| 42 | $run_on_batteries = parse_boolint($prefs, "run_on_batteries"); |
||
| 43 | $run_if_user_active = parse_boolint($prefs, "run_if_user_active"); |
||
| 44 | $start_hour = parse_num($prefs, "<start_hour>"); |
||
| 45 | $end_hour = parse_num($prefs, "<end_hour>"); |
||
| 46 | $net_start_hour = parse_num($prefs, "<net_start_hour>"); |
||
| 47 | $net_end_hour = parse_num($prefs, "<net_end_hour>"); |
||
| 48 | $leave_apps_in_memory = parse_boolint($prefs, "leave_apps_in_memory"); |
||
| 49 | $confirm_before_connecting = parse_boolint($prefs, "confirm_before_connecting"); |
||
| 50 | $hangup_if_dialed = parse_boolint($prefs, "hangup_if_dialed"); |
||
| 51 | $work_buf_min_days = parse_num($prefs, "<work_buf_min_days>"); |
||
| 52 | $max_cpus = parse_num($prefs, "<max_cpus>"); |
||
| 53 | $cpu_scheduling_period_minutes = parse_num($prefs, "<cpu_scheduling_period_minutes>"); |
||
| 54 | $disk_interval = parse_num($prefs, "<disk_interval>"); |
||
| 55 | $disk_max_used_gb = parse_num($prefs, "<disk_max_used_gb>"); |
||
| 56 | $disk_max_used_pct = parse_num($prefs, "<disk_max_used_pct>"); |
||
| 57 | $disk_min_free_gb = parse_num($prefs, "<disk_min_free_gb>"); |
||
| 58 | $vm_max_used_pct = parse_num($prefs, "<vm_max_used_pct>"); |
||
| 59 | $idle_time_to_run = parse_num($prefs, "<idle_time_to_run>"); |
||
| 60 | $max_bytes_sec_up = parse_num($prefs, "<max_bytes_sec_up>"); |
||
| 61 | $max_bytes_sec_down = parse_num($prefs, "<max_bytes_sec_down>"); |
||
| 62 | $query = "insert into puser values |
||
| 63 | ($user->id, |
||
| 64 | $user->create_time, |
||
| 65 | '$user->email_addr', |
||
| 66 | '$user->country', |
||
| 67 | $user->total_credit, |
||
| 68 | '$user->venue', |
||
| 69 | $run_on_batteries, |
||
| 70 | $run_if_user_active, |
||
| 71 | $start_hour, |
||
| 72 | $end_hour, |
||
| 73 | $net_start_hour, |
||
| 74 | $net_end_hour, |
||
| 75 | $leave_apps_in_memory, |
||
| 76 | $confirm_before_connecting, |
||
| 77 | $hangup_if_dialed, |
||
| 78 | $work_buf_min_days, |
||
| 79 | $max_cpus, |
||
| 80 | $cpu_scheduling_period_minutes, |
||
| 81 | $disk_interval, |
||
| 82 | $disk_max_used_gb, |
||
| 83 | $disk_max_used_pct, |
||
| 84 | $disk_min_free_gb, |
||
| 85 | $vm_max_used_pct, |
||
| 86 | $idle_time_to_run, |
||
| 87 | $max_bytes_sec_up, |
||
| 88 | $max_bytes_sec_down) |
||
| 89 | "; |
||
| 90 | $retval = _mysql_query($query); |
||
| 91 | if (!$retval) { |
||
| 92 | echo _mysql_error(); |
||
| 93 | } |
||
| 104 |
This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.