| Conditions | 41 |
| Paths | > 20000 |
| Total Lines | 185 |
| Code Lines | 98 |
| 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 | * Sanitize the action command |
||
| 40 | * |
||
| 41 | * @author Andreas Gohr <[email protected]> |
||
| 42 | * |
||
| 43 | * @param array|string $act |
||
| 44 | * @return string |
||
| 45 | */ |
||
| 46 | function act_clean($act){ |
||
| 47 | // check if the action was given as array key |
||
| 48 | if(is_array($act)){ |
||
| 49 | list($act) = array_keys($act); |
||
| 50 | } |
||
| 51 | |||
| 52 | //remove all bad chars |
||
| 53 | $act = strtolower($act); |
||
| 54 | $act = preg_replace('/[^1-9a-z_]+/','',$act); |
||
| 55 | |||
| 56 | if($act == 'export_html') $act = 'export_xhtml'; |
||
| 57 | if($act == 'export_htmlbody') $act = 'export_xhtmlbody'; |
||
| 58 | |||
| 59 | if($act === '') $act = 'show'; |
||
| 60 | return $act; |
||
| 61 | } |
||
| 62 | |||
| 63 | |||
| 64 | /** |
||
| 65 | * Handle 'draftdel' |
||
| 66 | * |
||
| 67 | * Deletes the draft for the current page and user |
||
| 68 | * |
||
| 69 | * @param string $act action command |
||
| 70 | * @return string action command |
||
| 71 | */ |
||
| 72 | function act_draftdel($act){ |
||
|
|
|||
| 73 | global $INFO; |
||
| 74 | @unlink($INFO['draft']); |
||
|
1 ignored issue
–
show
|
|||
| 75 | $INFO['draft'] = null; |
||
| 76 | return 'show'; |
||
| 77 | } |
||
| 78 | |||
| 79 | /** |
||
| 80 | * Do a redirect after receiving post data |
||
| 81 | * |
||
| 82 | * Tries to add the section id as hash mark after section editing |
||
| 83 | * |
||
| 84 | * @param string $id page id |
||
| 85 | * @param string $preact action command before redirect |
||
| 86 | */ |
||
| 87 | function act_redirect($id,$preact){ |
||
| 88 | global $PRE; |
||
| 89 | global $TEXT; |
||
| 90 | |||
| 91 | $opts = array( |
||
| 92 | 'id' => $id, |
||
| 93 | 'preact' => $preact |
||
| 94 | ); |
||
| 95 | //get section name when coming from section edit |
||
| 96 | if($PRE && preg_match('/^\s*==+([^=\n]+)/',$TEXT,$match)){ |
||
| 97 | $check = false; //Byref |
||
| 98 | $opts['fragment'] = sectionID($match[0], $check); |
||
| 99 | } |
||
| 100 | |||
| 101 | trigger_event('ACTION_SHOW_REDIRECT',$opts,'act_redirect_execute'); |
||
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * Execute the redirect |
||
| 106 | * |
||
| 107 | * @param array $opts id and fragment for the redirect and the preact |
||
| 108 | */ |
||
| 109 | function act_redirect_execute($opts){ |
||
| 110 | $go = wl($opts['id'],'',true); |
||
| 111 | if(isset($opts['fragment'])) $go .= '#'.$opts['fragment']; |
||
| 112 | |||
| 113 | //show it |
||
| 114 | send_redirect($go); |
||
| 115 | } |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Validate POST data |
||
| 119 | * |
||
| 120 | * Validates POST data for a subscribe or unsubscribe request. This is the |
||
| 121 | * default action for the event ACTION_HANDLE_SUBSCRIBE. |
||
| 122 | * |
||
| 123 | * @author Adrian Lang <[email protected]> |
||
| 124 | * |
||
| 125 | * @param array &$params the parameters: target, style and action |
||
| 126 | * @throws Exception |
||
| 127 | */ |
||
| 128 | function subscription_handle_post(&$params) { |
||
| 129 | global $INFO; |
||
| 130 | global $lang; |
||
| 131 | /* @var Input $INPUT */ |
||
| 132 | global $INPUT; |
||
| 133 | |||
| 134 | // Get and validate parameters. |
||
| 135 | if (!isset($params['target'])) { |
||
| 136 | throw new Exception('no subscription target given'); |
||
| 137 | } |
||
| 138 | $target = $params['target']; |
||
| 139 | $valid_styles = array('every', 'digest'); |
||
| 140 | if (substr($target, -1, 1) === ':') { |
||
| 141 | // Allow “list” subscribe style since the target is a namespace. |
||
| 142 | $valid_styles[] = 'list'; |
||
| 143 | } |
||
| 144 | $style = valid_input_set('style', $valid_styles, $params, |
||
| 145 | 'invalid subscription style given'); |
||
| 146 | $action = valid_input_set('action', array('subscribe', 'unsubscribe'), |
||
| 147 | $params, 'invalid subscription action given'); |
||
| 148 | |||
| 149 | // Check other conditions. |
||
| 150 | if ($action === 'subscribe') { |
||
| 151 | if ($INFO['userinfo']['mail'] === '') { |
||
| 152 | throw new Exception($lang['subscr_subscribe_noaddress']); |
||
| 153 | } |
||
| 154 | } elseif ($action === 'unsubscribe') { |
||
| 155 | $is = false; |
||
| 156 | foreach($INFO['subscribed'] as $subscr) { |
||
| 157 | if ($subscr['target'] === $target) { |
||
| 158 | $is = true; |
||
| 159 | } |
||
| 160 | } |
||
| 161 | if ($is === false) { |
||
| 162 | throw new Exception(sprintf($lang['subscr_not_subscribed'], |
||
| 163 | $INPUT->server->str('REMOTE_USER'), |
||
| 164 | prettyprint_id($target))); |
||
| 165 | } |
||
| 166 | // subscription_set deletes a subscription if style = null. |
||
| 167 | $style = null; |
||
| 168 | } |
||
| 169 | |||
| 170 | $params = compact('target', 'style', 'action'); |
||
| 171 | } |
||
| 172 | |||
| 173 | //Setup VIM: ex: et ts=2 : |
||
| 174 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.