| Conditions | 7 | 
| Paths | 12 | 
| Total Lines | 75 | 
| Code Lines | 55 | 
| 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  | 
            ||
| 36 |     public function preProcess() { | 
            ||
| 37 | global $ID;  | 
            ||
| 38 | global $REV;  | 
            ||
| 39 | global $conf;  | 
            ||
| 40 | global $lang;  | 
            ||
| 41 | |||
| 42 | $pre = '';  | 
            ||
| 43 | $post = '';  | 
            ||
| 44 | $headers = array();  | 
            ||
| 45 | |||
| 46 | // search engines: never cache exported docs! (Google only currently)  | 
            ||
| 47 | $headers['X-Robots-Tag'] = 'noindex';  | 
            ||
| 48 | |||
| 49 | $mode = substr($this->actionname, 7);  | 
            ||
| 50 |         switch($mode) { | 
            ||
| 51 | case 'raw':  | 
            ||
| 52 | $headers['Content-Type'] = 'text/plain; charset=utf-8';  | 
            ||
| 53 | $headers['Content-Disposition'] = 'attachment; filename=' . noNS($ID) . '.txt';  | 
            ||
| 54 | $output = rawWiki($ID, $REV);  | 
            ||
| 55 | break;  | 
            ||
| 56 | case 'xhtml':  | 
            ||
| 57 | $pre .= '<!DOCTYPE html>' . DOKU_LF;  | 
            ||
| 58 | $pre .= '<html lang="' . $conf['lang'] . '" dir="' . $lang['direction'] . '">' . DOKU_LF;  | 
            ||
| 59 | $pre .= '<head>' . DOKU_LF;  | 
            ||
| 60 | $pre .= ' <meta charset="utf-8" />' . DOKU_LF; // FIXME improve wrapper  | 
            ||
| 61 | $pre .= ' <title>' . $ID . '</title>' . DOKU_LF;  | 
            ||
| 62 | |||
| 63 | // get metaheaders  | 
            ||
| 64 | ob_start();  | 
            ||
| 65 | tpl_metaheaders();  | 
            ||
| 66 | $pre .= ob_get_clean();  | 
            ||
| 67 | |||
| 68 | $pre .= '</head>' . DOKU_LF;  | 
            ||
| 69 | $pre .= '<body>' . DOKU_LF;  | 
            ||
| 70 | $pre .= '<div class="dokuwiki export">' . DOKU_LF;  | 
            ||
| 71 | |||
| 72 | // get toc  | 
            ||
| 73 | $pre .= tpl_toc(true);  | 
            ||
| 74 | |||
| 75 | $headers['Content-Type'] = 'text/html; charset=utf-8';  | 
            ||
| 76 | $output = p_wiki_xhtml($ID, $REV, false);  | 
            ||
| 77 | |||
| 78 | $post .= '</div>' . DOKU_LF;  | 
            ||
| 79 | $post .= '</body>' . DOKU_LF;  | 
            ||
| 80 | $post .= '</html>' . DOKU_LF;  | 
            ||
| 81 | break;  | 
            ||
| 82 | case 'xhtmlbody':  | 
            ||
| 83 | $headers['Content-Type'] = 'text/html; charset=utf-8';  | 
            ||
| 84 | $output = p_wiki_xhtml($ID, $REV, false);  | 
            ||
| 85 | break;  | 
            ||
| 86 | default:  | 
            ||
| 87 | $output = p_cached_output(wikiFN($ID, $REV), $mode, $ID);  | 
            ||
| 88 | $headers = p_get_metadata($ID, "format $mode");  | 
            ||
| 89 | break;  | 
            ||
| 90 | }  | 
            ||
| 91 | |||
| 92 | // prepare event data  | 
            ||
| 93 | $data = array();  | 
            ||
| 94 | $data['id'] = $ID;  | 
            ||
| 95 | $data['mode'] = $mode;  | 
            ||
| 96 | $data['headers'] = $headers;  | 
            ||
| 97 | $data['output'] =& $output;  | 
            ||
| 98 | |||
| 99 |         trigger_event('ACTION_EXPORT_POSTPROCESS', $data); | 
            ||
| 100 | |||
| 101 |         if(!empty($data['output'])) { | 
            ||
| 102 |             if(is_array($data['headers'])) foreach($data['headers'] as $key => $val) { | 
            ||
| 103 |                 header("$key: $val"); | 
            ||
| 104 | }  | 
            ||
| 105 | print $pre . $data['output'] . $post;  | 
            ||
| 106 | exit;  | 
            ||
| 107 | }  | 
            ||
| 108 | |||
| 109 | throw new ActionAbort();  | 
            ||
| 110 | }  | 
            ||
| 111 | |||
| 113 |