Conditions | 17 |
Paths | 268 |
Total Lines | 106 |
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 |
||
54 | function load_autoload($name){ |
||
55 | static $classes = null; |
||
56 | if($classes === null) $classes = array( |
||
57 | 'Diff' => DOKU_INC.'inc/DifferenceEngine.php', |
||
58 | 'UnifiedDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php', |
||
59 | 'TableDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php', |
||
60 | 'cache' => DOKU_INC.'inc/cache.php', |
||
61 | 'cache_parser' => DOKU_INC.'inc/cache.php', |
||
62 | 'cache_instructions' => DOKU_INC.'inc/cache.php', |
||
63 | 'cache_renderer' => DOKU_INC.'inc/cache.php', |
||
64 | 'Input' => DOKU_INC.'inc/Input.class.php', |
||
65 | 'JpegMeta' => DOKU_INC.'inc/JpegMeta.php', |
||
66 | 'SimplePie' => DOKU_INC.'inc/SimplePie.php', |
||
67 | 'FeedParser' => DOKU_INC.'inc/FeedParser.php', |
||
68 | 'IXR_Server' => DOKU_INC.'inc/IXR_Library.php', |
||
69 | 'IXR_Client' => DOKU_INC.'inc/IXR_Library.php', |
||
70 | 'IXR_Error' => DOKU_INC.'inc/IXR_Library.php', |
||
71 | 'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php', |
||
72 | 'SafeFN' => DOKU_INC.'inc/SafeFN.class.php', |
||
73 | 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php', |
||
74 | 'Mailer' => DOKU_INC.'inc/Mailer.class.php', |
||
75 | |||
76 | 'Doku_Handler' => DOKU_INC.'inc/parser/handler.php', |
||
77 | 'Doku_Renderer' => DOKU_INC.'inc/parser/renderer.php', |
||
78 | 'Doku_Renderer_xhtml' => DOKU_INC.'inc/parser/xhtml.php', |
||
79 | 'Doku_Renderer_code' => DOKU_INC.'inc/parser/code.php', |
||
80 | 'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php', |
||
81 | 'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php', |
||
82 | ); |
||
83 | |||
84 | if(isset($classes[$name])){ |
||
85 | require ($classes[$name]); |
||
86 | return true; |
||
87 | } |
||
88 | |||
89 | // namespace to directory conversion |
||
90 | $name = str_replace('\\', '/', $name); |
||
91 | |||
92 | // test namespace |
||
93 | if(substr($name, 0, 14) === 'dokuwiki/test/') { |
||
94 | $file = DOKU_INC . '_test/' . substr($name, 14) . '.php'; |
||
95 | if(file_exists($file)) { |
||
96 | require $file; |
||
97 | return true; |
||
98 | } |
||
99 | } |
||
100 | |||
101 | // plugin namespace |
||
102 | if(substr($name, 0, 16) === 'dokuwiki/plugin/') { |
||
103 | $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace |
||
104 | $file = DOKU_PLUGIN . substr($name, 16) . '.php'; |
||
105 | if(file_exists($file)) { |
||
106 | try { |
||
107 | require $file; |
||
108 | } catch (\Throwable $e) { |
||
109 | \dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading plugin $name"); |
||
110 | } |
||
111 | return true; |
||
112 | } |
||
113 | } |
||
114 | |||
115 | // template namespace |
||
116 | if(substr($name, 0, 18) === 'dokuwiki/template/') { |
||
117 | $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace |
||
118 | $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php'; |
||
119 | if(file_exists($file)) { |
||
120 | try { |
||
121 | require $file; |
||
122 | } catch (\Throwable $e) { |
||
123 | \dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading template $name"); |
||
124 | } |
||
125 | return true; |
||
126 | } |
||
127 | } |
||
128 | |||
129 | // our own namespace |
||
130 | if(substr($name, 0, 9) === 'dokuwiki/') { |
||
131 | $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php'; |
||
132 | if(file_exists($file)) { |
||
133 | require $file; |
||
134 | return true; |
||
135 | } |
||
136 | } |
||
137 | |||
138 | // Plugin loading |
||
139 | if(preg_match( |
||
140 | '/^(' . implode('|', PluginController::PLUGIN_TYPES) . ')_plugin_(' . |
||
141 | DOKU_PLUGIN_NAME_REGEX . |
||
142 | ')(?:_([^_]+))?$/', |
||
143 | $name, |
||
144 | $m |
||
145 | )) { |
||
146 | // try to load the wanted plugin file |
||
147 | $c = ((count($m) === 4) ? "/{$m[3]}" : ''); |
||
148 | $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php"; |
||
149 | if(file_exists($plg)){ |
||
150 | try { |
||
151 | require $plg; |
||
152 | } catch (\Throwable $e) { |
||
153 | \dokuwiki\ErrorHandler::showExceptionMsg($e, "Error loading plugin {$m[2]}"); |
||
154 | } |
||
155 | } |
||
156 | return true; |
||
157 | } |
||
158 | return false; |
||
159 | } |
||
160 | |||
161 |