| Conditions | 17 | 
| Paths | 2176 | 
| Total Lines | 128 | 
| Code Lines | 81 | 
| Lines | 0 | 
| Ratio | 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  | 
            ||
| 29 | function js_out(){ | 
            ||
| 30 | global $conf;  | 
            ||
| 31 | global $lang;  | 
            ||
| 32 | global $config_cascade;  | 
            ||
| 33 | global $INPUT;  | 
            ||
| 34 | |||
| 35 | // decide from where to get the template  | 
            ||
| 36 |     $tpl = trim(preg_replace('/[^\w-]+/','',$INPUT->str('t'))); | 
            ||
| 37 | if(!$tpl) $tpl = $conf['template'];  | 
            ||
| 38 | |||
| 39 | // The generated script depends on some dynamic options  | 
            ||
| 40 |     $cache = new cache('scripts'.$_SERVER['HTTP_HOST'].$_SERVER['SERVER_PORT'].DOKU_BASE.$tpl,'.js'); | 
            ||
| 41 | $cache->_event = 'JS_CACHE_USE';  | 
            ||
| 
                                                                                                    
                        
                         | 
                |||
| 42 | |||
| 43 | // load minified version for some files  | 
            ||
| 44 | $min = $conf['compress'] ? '.min' : '';  | 
            ||
| 45 | |||
| 46 | // array of core files  | 
            ||
| 47 | $files = array(  | 
            ||
| 48 | DOKU_INC."lib/scripts/jquery/jquery$min.js",  | 
            ||
| 49 | DOKU_INC.'lib/scripts/jquery/jquery.cookie.js',  | 
            ||
| 50 | DOKU_INC."lib/scripts/jquery/jquery-ui$min.js",  | 
            ||
| 51 | DOKU_INC."lib/scripts/jquery/jquery-migrate$min.js",  | 
            ||
| 52 | DOKU_INC.'inc/lang/'.$conf['lang'].'/jquery.ui.datepicker.js',  | 
            ||
| 53 | DOKU_INC."lib/scripts/fileuploader.js",  | 
            ||
| 54 | DOKU_INC."lib/scripts/fileuploaderextended.js",  | 
            ||
| 55 | DOKU_INC.'lib/scripts/helpers.js',  | 
            ||
| 56 | DOKU_INC.'lib/scripts/delay.js',  | 
            ||
| 57 | DOKU_INC.'lib/scripts/cookie.js',  | 
            ||
| 58 | DOKU_INC.'lib/scripts/script.js',  | 
            ||
| 59 | DOKU_INC.'lib/scripts/qsearch.js',  | 
            ||
| 60 | DOKU_INC.'lib/scripts/tree.js',  | 
            ||
| 61 | DOKU_INC.'lib/scripts/index.js',  | 
            ||
| 62 | DOKU_INC.'lib/scripts/textselection.js',  | 
            ||
| 63 | DOKU_INC.'lib/scripts/toolbar.js',  | 
            ||
| 64 | DOKU_INC.'lib/scripts/edit.js',  | 
            ||
| 65 | DOKU_INC.'lib/scripts/editor.js',  | 
            ||
| 66 | DOKU_INC.'lib/scripts/locktimer.js',  | 
            ||
| 67 | DOKU_INC.'lib/scripts/linkwiz.js',  | 
            ||
| 68 | DOKU_INC.'lib/scripts/media.js',  | 
            ||
| 69 | DOKU_INC.'lib/scripts/compatibility.js',  | 
            ||
| 70 | # disabled for FS#1958 DOKU_INC.'lib/scripts/hotkeys.js',  | 
            ||
| 71 | DOKU_INC.'lib/scripts/behaviour.js',  | 
            ||
| 72 | DOKU_INC.'lib/scripts/page.js',  | 
            ||
| 73 | tpl_incdir($tpl).'script.js',  | 
            ||
| 74 | );  | 
            ||
| 75 | |||
| 76 | // add possible plugin scripts and userscript  | 
            ||
| 77 | $files = array_merge($files,js_pluginscripts());  | 
            ||
| 78 |     if(!empty($config_cascade['userscript']['default'])) { | 
            ||
| 79 |         foreach($config_cascade['userscript']['default'] as $userscript) { | 
            ||
| 80 | $files[] = $userscript;  | 
            ||
| 81 | }  | 
            ||
| 82 | }  | 
            ||
| 83 | |||
| 84 |     $cache_files = array_merge($files, getConfigFiles('main')); | 
            ||
| 85 | $cache_files[] = __FILE__;  | 
            ||
| 86 | |||
| 87 | // check cache age & handle conditional request  | 
            ||
| 88 | // This may exit if a cache can be used  | 
            ||
| 89 |     $cache_ok = $cache->useCache(array('files' => $cache_files)); | 
            ||
| 90 | http_cached($cache->cache, $cache_ok);  | 
            ||
| 91 | |||
| 92 | // start output buffering and build the script  | 
            ||
| 93 | ob_start();  | 
            ||
| 94 | |||
| 95 | $json = new JSON();  | 
            ||
| 96 | // add some global variables  | 
            ||
| 97 | print "var DOKU_BASE = '".DOKU_BASE."';";  | 
            ||
| 98 | print "var DOKU_TPL = '".tpl_basedir($tpl)."';";  | 
            ||
| 99 | print "var DOKU_COOKIE_PARAM = " . $json->encode(  | 
            ||
| 100 | array(  | 
            ||
| 101 | 'path' => empty($conf['cookiedir']) ? DOKU_REL : $conf['cookiedir'],  | 
            ||
| 102 | 'secure' => $conf['securecookie'] && is_ssl()  | 
            ||
| 103 | )).";";  | 
            ||
| 104 | // FIXME: Move those to JSINFO  | 
            ||
| 105 |     print "var DOKU_UHN    = ".((int) useHeading('navigation')).";"; | 
            ||
| 106 |     print "var DOKU_UHC    = ".((int) useHeading('content')).";"; | 
            ||
| 107 | |||
| 108 | // load JS specific translations  | 
            ||
| 109 | $lang['js']['plugins'] = js_pluginstrings();  | 
            ||
| 110 | $templatestrings = js_templatestrings($tpl);  | 
            ||
| 111 |     if(!empty($templatestrings)) { | 
            ||
| 112 | $lang['js']['template'] = $templatestrings;  | 
            ||
| 113 | }  | 
            ||
| 114 | echo 'LANG = '.$json->encode($lang['js']).";\n";  | 
            ||
| 115 | |||
| 116 | // load toolbar  | 
            ||
| 117 |     toolbar_JSdefines('toolbar'); | 
            ||
| 118 | |||
| 119 | // load files  | 
            ||
| 120 |     foreach($files as $file){ | 
            ||
| 121 | if(!file_exists($file)) continue;  | 
            ||
| 122 | $ismin = (substr($file,-7) == '.min.js');  | 
            ||
| 123 | $debugjs = ($conf['allowdebug'] && strpos($file, DOKU_INC.'lib/scripts/') !== 0);  | 
            ||
| 124 | |||
| 125 | echo "\n\n/* XXXXXXXXXX begin of ".str_replace(DOKU_INC, '', $file) ." XXXXXXXXXX */\n\n";  | 
            ||
| 126 | if($ismin) echo "\n/* BEGIN NOCOMPRESS */\n";  | 
            ||
| 127 |         if ($debugjs) echo "\ntry {\n"; | 
            ||
| 128 | js_load($file);  | 
            ||
| 129 |         if ($debugjs) echo "\n} catch (e) {\n   logError(e, '".str_replace(DOKU_INC, '', $file)."');\n}\n"; | 
            ||
| 130 | if($ismin) echo "\n/* END NOCOMPRESS */\n";  | 
            ||
| 131 | echo "\n\n/* XXXXXXXXXX end of " . str_replace(DOKU_INC, '', $file) . " XXXXXXXXXX */\n\n";  | 
            ||
| 132 | }  | 
            ||
| 133 | |||
| 134 | // init stuff  | 
            ||
| 135 |     if($conf['locktime'] != 0){ | 
            ||
| 136 |         js_runonstart("dw_locktimer.init(".($conf['locktime'] - 60).",".$conf['usedraft'].")"); | 
            ||
| 137 | }  | 
            ||
| 138 | // init hotkeys - must have been done after init of toolbar  | 
            ||
| 139 | # disabled for FS#1958    js_runonstart('initializeHotkeys()'); | 
            ||
| 140 | |||
| 141 | // end output buffering and get contents  | 
            ||
| 142 | $js = ob_get_contents();  | 
            ||
| 143 | ob_end_clean();  | 
            ||
| 144 | |||
| 145 | // strip any source maps  | 
            ||
| 146 | stripsourcemaps($js);  | 
            ||
| 147 | |||
| 148 | // compress whitespace and comments  | 
            ||
| 149 |     if($conf['compress']){ | 
            ||
| 150 | $js = js_compress($js);  | 
            ||
| 151 | }  | 
            ||
| 152 | |||
| 153 | $js .= "\n"; // https://bugzilla.mozilla.org/show_bug.cgi?id=316033  | 
            ||
| 154 | |||
| 155 | http_cached_finish($cache->cache, $js);  | 
            ||
| 156 | }  | 
            ||
| 157 | |||
| 453 | 
This check looks for access to properties that are not accessible from the current context.
If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.