Conditions | 8 |
Paths | 9 |
Total Lines | 53 |
Code Lines | 35 |
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 |
||
35 | public function handleAjaxCallAcl(Doku_Event $event, $param) |
||
|
|||
36 | { |
||
37 | if ($event->data !== 'plugin_acl') { |
||
38 | return; |
||
39 | } |
||
40 | $event->stopPropagation(); |
||
41 | $event->preventDefault(); |
||
42 | |||
43 | global $ID; |
||
44 | global $INPUT; |
||
45 | |||
46 | if (!auth_isadmin()) { |
||
47 | echo 'for admins only'; |
||
48 | return; |
||
49 | } |
||
50 | if (!checkSecurityToken()) { |
||
51 | echo 'CRSF Attack'; |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $ID = getID(); |
||
56 | |||
57 | /** @var $acl admin_plugin_acl */ |
||
58 | $acl = plugin_load('admin', 'acl'); |
||
59 | $acl->handle(); |
||
60 | |||
61 | $ajax = $INPUT->str('ajax'); |
||
62 | header('Content-Type: text/html; charset=utf-8'); |
||
63 | |||
64 | if ($ajax == 'info') { |
||
65 | $acl->printInfo(); |
||
66 | } elseif ($ajax == 'tree') { |
||
67 | $ns = $INPUT->str('ns'); |
||
68 | if ($ns == '*') { |
||
69 | $ns = ''; |
||
70 | } |
||
71 | $ns = cleanID($ns); |
||
72 | $lvl = count(explode(':', $ns)); |
||
73 | $ns = utf8_encodeFN(str_replace(':', '/', $ns)); |
||
74 | |||
75 | $data = $acl->makeTree($ns, $ns); |
||
76 | |||
77 | foreach (array_keys($data) as $item) { |
||
78 | $data[$item]['level'] = $lvl + 1; |
||
79 | } |
||
80 | echo html_buildlist( |
||
81 | $data, |
||
82 | 'acl', |
||
83 | array($acl, 'makeTreeItem'), |
||
84 | array($acl, 'makeListItem') |
||
85 | ); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.