Failed Conditions
Push — psr2 ( 42c287...d2778c )
by Andreas
03:35
created

load.php ➔ load_autoload()   D

Complexity

Conditions 14
Paths 192

Size

Total Lines 124
Code Lines 90

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 14
eloc 90
nc 192
nop 1
dl 0
loc 124
rs 4.6283
c 0
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
/**
3
 * Load all internal libraries and setup class autoloader
4
 *
5
 * @author Andreas Gohr <[email protected]>
6
 */
7
8
// setup class autoloader
9
spl_autoload_register('load_autoload');
10
11
// require all the common libraries
12
// for a few of these order does matter
13
require_once(DOKU_INC.'inc/actions.php');
14
require_once(DOKU_INC.'inc/changelog.php');
15
require_once(DOKU_INC.'inc/common.php');
16
require_once(DOKU_INC.'inc/confutils.php');
17
require_once(DOKU_INC.'inc/pluginutils.php');
18
require_once(DOKU_INC.'inc/events.php');
19
require_once(DOKU_INC.'inc/form.php');
20
require_once(DOKU_INC.'inc/fulltext.php');
21
require_once(DOKU_INC.'inc/html.php');
22
require_once(DOKU_INC.'inc/httputils.php');
23
require_once(DOKU_INC.'inc/indexer.php');
24
require_once(DOKU_INC.'inc/infoutils.php');
25
require_once(DOKU_INC.'inc/io.php');
26
require_once(DOKU_INC.'inc/mail.php');
27
require_once(DOKU_INC.'inc/media.php');
28
require_once(DOKU_INC.'inc/pageutils.php');
29
require_once(DOKU_INC.'inc/parserutils.php');
30
require_once(DOKU_INC.'inc/search.php');
31
require_once(DOKU_INC.'inc/subscription.php');
32
require_once(DOKU_INC.'inc/template.php');
33
require_once(DOKU_INC.'inc/toolbar.php');
34
require_once(DOKU_INC.'inc/utf8.php');
35
require_once(DOKU_INC.'inc/auth.php');
36
require_once(DOKU_INC.'inc/compatibility.php');
37
38
/**
39
 * spl_autoload_register callback
40
 *
41
 * Contains a static list of DokuWiki's core classes and automatically
42
 * require()s their associated php files when an object is instantiated.
43
 *
44
 * @author Andreas Gohr <[email protected]>
45
 * @todo   add generic loading of renderers and auth backends
46
 *
47
 * @param string $name
48
 *
49
 * @return bool
50
 */
51
function load_autoload($name){
52
    static $classes = null;
53
    if(is_null($classes)) $classes = array(
54
        'DokuHTTPClient'        => DOKU_INC.'inc/HTTPClient.php',
55
        'HTTPClient'            => DOKU_INC.'inc/HTTPClient.php',
56
        'JSON'                  => DOKU_INC.'inc/JSON.php',
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
        'Doku_Event'            => DOKU_INC.'inc/events.php',
65
        'Doku_Event_Handler'    => DOKU_INC.'inc/events.php',
66
        'Input'                 => DOKU_INC.'inc/Input.class.php',
67
        'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
68
        'SimplePie'             => DOKU_INC.'inc/SimplePie.php',
69
        'FeedParser'            => DOKU_INC.'inc/FeedParser.php',
70
        'IXR_Server'            => DOKU_INC.'inc/IXR_Library.php',
71
        'IXR_Client'            => DOKU_INC.'inc/IXR_Library.php',
72
        'IXR_Error'             => DOKU_INC.'inc/IXR_Library.php',
73
        'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php',
74
        'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php',
75
        'SafeFN'                => DOKU_INC.'inc/SafeFN.class.php',
76
        'Sitemapper'            => DOKU_INC.'inc/Sitemapper.php',
77
        'PassHash'              => DOKU_INC.'inc/PassHash.class.php',
78
        'Mailer'                => DOKU_INC.'inc/Mailer.class.php',
79
        'RemoteAPI'             => DOKU_INC.'inc/remote.php',
80
        'RemoteAPICore'         => DOKU_INC.'inc/RemoteAPICore.php',
81
        'Subscription'          => DOKU_INC.'inc/subscription.php',
82
83
        'DokuWiki_PluginInterface' => DOKU_INC.'inc/PluginInterface.php',
84
        'DokuWiki_PluginTrait'     => DOKU_INC.'inc/PluginTrait.php',
85
        'DokuWiki_Plugin'          => DOKU_INC.'inc/Plugin.php',
86
87
88
        'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
89
        'DokuWiki_Admin_Plugin'  => DOKU_PLUGIN.'admin.php',
90
        'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php',
91
        'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php',
92
        'DokuWiki_Auth_Plugin'   => DOKU_PLUGIN.'auth.php',
93
        'DokuWiki_CLI_Plugin'    => DOKU_PLUGIN.'cli.php',
94
95
        'Doku_Lexer'            => DOKU_INC.'inc/parser/lexer.php',
96
        'Doku_Handler'          => DOKU_INC.'inc/parser/handler.php',
97
        'Doku_Parser_Mode'      => DOKU_INC.'inc/parser/parser.php',
98
        'Doku_Parser_Mode_Plugin' => DOKU_INC.'inc/parser/parser.php',
99
        'Doku_Renderer'          => DOKU_INC.'inc/parser/renderer.php',
100
        'Doku_Renderer_xhtml'    => DOKU_INC.'inc/parser/xhtml.php',
101
        'Doku_Renderer_code'     => DOKU_INC.'inc/parser/code.php',
102
        'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
103
        'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',
104
105
        'DokuCLI'                => DOKU_INC.'inc/cli.php',
106
        'DokuCLI_Options'        => DOKU_INC.'inc/cli.php',
107
        'DokuCLI_Colors'         => DOKU_INC.'inc/cli.php',
108
109
    );
110
111
    if(isset($classes[$name])){
112
        require ($classes[$name]);
113
        return true;
114
    }
115
116
    // namespace to directory conversion
117
    $name = str_replace('\\', '/', $name);
118
119
    // test namespace
120
    if(substr($name, 0, 14) == 'dokuwiki/test/') {
121
        $file = DOKU_INC . '_test/' . substr($name, 14) . '.php';
122
        if(file_exists($file)) {
123
            require $file;
124
            return true;
125
        }
126
    }
127
128
    // plugin namespace
129
    if(substr($name, 0, 16) == 'dokuwiki/plugin/') {
130
        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
131
        $file = DOKU_PLUGIN . substr($name, 16) . '.php';
132
        if(file_exists($file)) {
133
            require $file;
134
            return true;
135
        }
136
    }
137
138
    // template namespace
139
    if(substr($name, 0, 18) == 'dokuwiki/template/') {
140
        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
141
        $file = DOKU_INC.'lib/tpl/' . substr($name, 18) . '.php';
142
        if(file_exists($file)) {
143
            require $file;
144
            return true;
145
        }
146
    }
147
148
    // our own namespace
149
    if(substr($name, 0, 9) == 'dokuwiki/') {
150
        $file = DOKU_INC . 'inc/' . substr($name, 9) . '.php';
151
        if(file_exists($file)) {
152
            require $file;
153
            return true;
154
        }
155
    }
156
157
    // Plugin loading
158
    if(preg_match(
159
        '/^(auth|helper|syntax|action|admin|renderer|remote|cli)_plugin_(' .
160
        DOKU_PLUGIN_NAME_REGEX .
161
        ')(?:_([^_]+))?$/',
162
        $name,
163
        $m
164
    )) {
165
        // try to load the wanted plugin file
166
        $c = ((count($m) === 4) ? "/{$m[3]}" : '');
167
        $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
168
        if(file_exists($plg)){
169
            require $plg;
170
        }
171
        return true;
172
    }
173
    return false;
174
}
175
176