Conditions | 15 |
Paths | 2 |
Total Lines | 75 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 | public 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])) { |
||
34 | $omap[$action] = array(); |
||
35 | } |
||
36 | |||
37 | array_push($omap[$action], $sequence); |
||
38 | } |
||
39 | |||
40 | print "<ul class='panel panel-scrollable hotkeys-help' style='height : 300px'>"; |
||
41 | |||
42 | $cur_section = ""; |
||
43 | foreach ($info as $section => $hotkeys) { |
||
44 | |||
45 | if ($cur_section) { |
||
46 | print "<li> </li>"; |
||
47 | } |
||
48 | print "<li><h3>".$section."</h3></li>"; |
||
49 | $cur_section = $section; |
||
50 | |||
51 | foreach ($hotkeys as $action => $description) { |
||
52 | |||
53 | if (is_array($omap[$action])) { |
||
54 | foreach ($omap[$action] as $sequence) { |
||
55 | if (strpos($sequence, "|") !== false) { |
||
56 | $sequence = substr($sequence, |
||
57 | strpos($sequence, "|") + 1, |
||
58 | strlen($sequence)); |
||
59 | } else { |
||
60 | $keys = explode(" ", $sequence); |
||
61 | |||
62 | for ($i = 0; $i < count($keys); $i++) { |
||
|
|||
63 | if (strlen($keys[$i]) > 1) { |
||
64 | $tmp = ''; |
||
65 | foreach (str_split($keys[$i]) as $c) { |
||
66 | switch ($c) { |
||
67 | case '*': |
||
68 | $tmp .= __('Shift').'+'; |
||
69 | break; |
||
70 | case '^': |
||
71 | $tmp .= __('Ctrl').'+'; |
||
72 | break; |
||
73 | default: |
||
74 | $tmp .= $c; |
||
75 | } |
||
76 | } |
||
77 | $keys[$i] = $tmp; |
||
78 | } |
||
79 | } |
||
80 | $sequence = join(" ", $keys); |
||
81 | } |
||
82 | |||
83 | print "<li>"; |
||
84 | print "<div class='hk'><code>$sequence</code></div>"; |
||
85 | print "<div class='desc'>$description</div>"; |
||
86 | print "</li>"; |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | } |
||
91 | |||
92 | print "</ul>"; |
||
93 | } |
||
94 | |||
95 | print "<footer class='text-center'>"; |
||
96 | print "<button dojoType='dijit.form.Button' |
||
97 | onclick=\"return dijit.byId('helpDlg').hide()\">".__('Close this window')."</button>"; |
||
98 | print "</footer>"; |
||
99 | |||
102 |
If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration: