Conditions | 14 |
Paths | 192 |
Total Lines | 119 |
Code Lines | 85 |
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 |
||
52 | function load_autoload($name){ |
||
53 | static $classes = null; |
||
54 | if(is_null($classes)) $classes = array( |
||
55 | 'DokuHTTPClient' => DOKU_INC.'inc/HTTPClient.php', |
||
56 | 'HTTPClient' => DOKU_INC.'inc/HTTPClient.php', |
||
57 | 'JSON' => DOKU_INC.'inc/JSON.php', |
||
58 | 'Diff' => DOKU_INC.'inc/DifferenceEngine.php', |
||
59 | 'UnifiedDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php', |
||
60 | 'TableDiffFormatter' => DOKU_INC.'inc/DifferenceEngine.php', |
||
61 | 'cache' => DOKU_INC.'inc/cache.php', |
||
62 | 'cache_parser' => DOKU_INC.'inc/cache.php', |
||
63 | 'cache_instructions' => DOKU_INC.'inc/cache.php', |
||
64 | 'cache_renderer' => DOKU_INC.'inc/cache.php', |
||
65 | 'Doku_Event' => DOKU_INC.'inc/events.php', |
||
66 | 'Doku_Event_Handler' => DOKU_INC.'inc/events.php', |
||
67 | 'Input' => DOKU_INC.'inc/Input.class.php', |
||
68 | 'JpegMeta' => DOKU_INC.'inc/JpegMeta.php', |
||
69 | 'SimplePie' => DOKU_INC.'inc/SimplePie.php', |
||
70 | 'FeedParser' => DOKU_INC.'inc/FeedParser.php', |
||
71 | 'IXR_Server' => DOKU_INC.'inc/IXR_Library.php', |
||
72 | 'IXR_Client' => DOKU_INC.'inc/IXR_Library.php', |
||
73 | 'IXR_Error' => DOKU_INC.'inc/IXR_Library.php', |
||
74 | 'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php', |
||
75 | 'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php', |
||
76 | 'SafeFN' => DOKU_INC.'inc/SafeFN.class.php', |
||
77 | 'Sitemapper' => DOKU_INC.'inc/Sitemapper.php', |
||
78 | 'PassHash' => DOKU_INC.'inc/PassHash.class.php', |
||
79 | 'Mailer' => DOKU_INC.'inc/Mailer.class.php', |
||
80 | 'Subscription' => DOKU_INC.'inc/subscription.php', |
||
81 | |||
82 | 'DokuWiki_PluginInterface' => DOKU_INC.'inc/PluginInterface.php', |
||
83 | 'DokuWiki_PluginTrait' => DOKU_INC.'inc/PluginTrait.php', |
||
84 | 'DokuWiki_Plugin' => DOKU_INC.'inc/Plugin.php', |
||
85 | |||
86 | |||
87 | 'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php', |
||
88 | 'DokuWiki_Admin_Plugin' => DOKU_PLUGIN.'admin.php', |
||
89 | 'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php', |
||
90 | 'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php', |
||
91 | 'DokuWiki_Auth_Plugin' => DOKU_PLUGIN.'auth.php', |
||
92 | 'DokuWiki_CLI_Plugin' => DOKU_PLUGIN.'cli.php', |
||
93 | |||
94 | 'Doku_Handler' => DOKU_INC.'inc/parser/handler.php', |
||
95 | 'Doku_Renderer' => DOKU_INC.'inc/parser/renderer.php', |
||
96 | 'Doku_Renderer_xhtml' => DOKU_INC.'inc/parser/xhtml.php', |
||
97 | 'Doku_Renderer_code' => DOKU_INC.'inc/parser/code.php', |
||
98 | 'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php', |
||
99 | 'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php', |
||
100 | |||
101 | 'DokuCLI' => DOKU_INC.'inc/cli.php', |
||
102 | 'DokuCLI_Options' => DOKU_INC.'inc/cli.php', |
||
103 | 'DokuCLI_Colors' => DOKU_INC.'inc/cli.php', |
||
104 | |||
105 | ); |
||
106 | |||
107 | if(isset($classes[$name])){ |
||
108 | require ($classes[$name]); |
||
109 | return true; |
||
110 | } |
||
111 | |||
112 | // namespace to directory conversion |
||
113 | $name = str_replace('\\', '/', $name); |
||
114 | |||
115 | // test namespace |
||
116 | if(substr($name, 0, 14) == 'dokuwiki/test/') { |
||
117 | $file = DOKU_INC . '_test/' . substr($name, 14) . '.php'; |
||
118 | if(file_exists($file)) { |
||
119 | require $file; |
||
120 | return true; |
||
121 | } |
||
122 | } |
||
123 | |||
124 | // plugin namespace |
||
125 | if(substr($name, 0, 16) == 'dokuwiki/plugin/') { |
||
126 | $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace |
||
127 | $file = DOKU_PLUGIN . substr($name, 16) . '.php'; |
||
128 | if(file_exists($file)) { |
||
129 | require $file; |
||
130 | return true; |
||
131 | } |
||
132 | } |
||
133 | |||
134 | // template namespace |
||
135 | if(substr($name, 0, 18) == 'dokuwiki/template/') { |
||
136 | $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace |
||
137 | $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php'; |
||
138 | if(file_exists($file)) { |
||
139 | require $file; |
||
140 | return true; |
||
141 | } |
||
142 | } |
||
143 | |||
144 | // our own namespace |
||
145 | if(substr($name, 0, 9) == 'dokuwiki/') { |
||
146 | $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php'; |
||
147 | if(file_exists($file)) { |
||
148 | require $file; |
||
149 | return true; |
||
150 | } |
||
151 | } |
||
152 | |||
153 | // Plugin loading |
||
154 | if(preg_match( |
||
155 | '/^(auth|helper|syntax|action|admin|renderer|remote|cli)_plugin_(' . |
||
156 | DOKU_PLUGIN_NAME_REGEX . |
||
157 | ')(?:_([^_]+))?$/', |
||
158 | $name, |
||
159 | $m |
||
160 | )) { |
||
161 | // try to load the wanted plugin file |
||
162 | $c = ((count($m) === 4) ? "/{$m[3]}" : ''); |
||
163 | $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php"; |
||
164 | if(file_exists($plg)){ |
||
165 | require $plg; |
||
166 | } |
||
167 | return true; |
||
168 | } |
||
169 | return false; |
||
170 | } |
||
171 | |||
172 |