Conditions | 13 |
Paths | 18 |
Total Lines | 62 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
24 | function help() { |
||
25 | $topic = clean_filename($_REQUEST["topic"]); // only one for now |
||
26 | |||
27 | if ($topic == "main") { |
||
28 | $info = get_hotkeys_info(); |
||
29 | $imap = get_hotkeys_map(); |
||
30 | $omap = array(); |
||
31 | |||
32 | foreach ($imap[1] as $sequence => $action) { |
||
33 | if (!isset($omap[$action])) $omap[$action] = array(); |
||
34 | |||
35 | array_push($omap[$action], $sequence); |
||
36 | } |
||
37 | |||
38 | print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>"; |
||
39 | |||
40 | $cur_section = ""; |
||
41 | foreach ($info as $section => $hotkeys) { |
||
42 | |||
43 | if ($cur_section) print "<li> </li>"; |
||
44 | print "<li><h3>" . $section . "</h3></li>"; |
||
45 | $cur_section = $section; |
||
46 | |||
47 | foreach ($hotkeys as $action => $description) { |
||
48 | |||
49 | if (is_array($omap[$action])) { |
||
50 | foreach ($omap[$action] as $sequence) { |
||
51 | if (strpos($sequence, "|") !== FALSE) { |
||
52 | $sequence = substr($sequence, |
||
53 | strpos($sequence, "|")+1, |
||
54 | strlen($sequence)); |
||
55 | } else { |
||
56 | $keys = explode(" ", $sequence); |
||
57 | |||
58 | for ($i = 0; $i < count($keys); $i++) { |
||
59 | if (strlen($keys[$i]) > 1) { |
||
60 | $tmp = ''; |
||
61 | foreach (str_split($keys[$i]) as $c) { |
||
62 | switch ($c) { |
||
63 | case '*': |
||
64 | $tmp .= __('Shift') . '+'; |
||
65 | break; |
||
66 | case '^': |
||
67 | $tmp .= __('Ctrl') . '+'; |
||
68 | break; |
||
69 | default: |
||
70 | $tmp .= $c; |
||
71 | } |
||
72 | } |
||
73 | $keys[$i] = $tmp; |
||
74 | } |
||
75 | } |
||
76 | $sequence = join(" ", $keys); |
||
77 | } |
||
78 | |||
79 | print "<li>"; |
||
80 | print "<div class='hk'><code>$sequence</code></div>"; |
||
81 | print "<div class='desc'>$description</div>"; |
||
82 | print "</li>"; |
||
83 | } |
||
84 | } |
||
85 | } |
||
86 | } |
||
98 |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.