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