Completed
Push — remoteapiGetversions ( b2f4ab...f28a57 )
by Gerrit
12:56 queued 07:54
created

load.php ➔ load_autoload()   D

Complexity

Conditions 9
Paths 28

Size

Total Lines 97
Code Lines 75

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 9
eloc 75
c 2
b 0
f 0
nc 28
nop 1
dl 0
loc 97
rs 4.9219

How to fix   Long Method   

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/blowfish.php');
14
require_once(DOKU_INC.'inc/actions.php');
15
require_once(DOKU_INC.'inc/changelog.php');
16
require_once(DOKU_INC.'inc/common.php');
17
require_once(DOKU_INC.'inc/confutils.php');
18
require_once(DOKU_INC.'inc/pluginutils.php');
19
require_once(DOKU_INC.'inc/plugin.php');
20
require_once(DOKU_INC.'inc/events.php');
21
require_once(DOKU_INC.'inc/form.php');
22
require_once(DOKU_INC.'inc/fulltext.php');
23
require_once(DOKU_INC.'inc/html.php');
24
require_once(DOKU_INC.'inc/httputils.php');
25
require_once(DOKU_INC.'inc/indexer.php');
26
require_once(DOKU_INC.'inc/infoutils.php');
27
require_once(DOKU_INC.'inc/io.php');
28
require_once(DOKU_INC.'inc/mail.php');
29
require_once(DOKU_INC.'inc/media.php');
30
require_once(DOKU_INC.'inc/pageutils.php');
31
require_once(DOKU_INC.'inc/parserutils.php');
32
require_once(DOKU_INC.'inc/search.php');
33
require_once(DOKU_INC.'inc/subscription.php');
34
require_once(DOKU_INC.'inc/template.php');
35
require_once(DOKU_INC.'inc/toolbar.php');
36
require_once(DOKU_INC.'inc/utf8.php');
37
require_once(DOKU_INC.'inc/auth.php');
38
require_once(DOKU_INC.'inc/compatibility.php');
39
40
/**
41
 * spl_autoload_register callback
42
 *
43
 * Contains a static list of DokuWiki's core classes and automatically
44
 * require()s their associated php files when an object is instantiated.
45
 *
46
 * @author Andreas Gohr <[email protected]>
47
 * @todo   add generic loading of renderers and auth backends
48
 */
49
function load_autoload($name){
50
    static $classes = null;
51
    if(is_null($classes)) $classes = array(
52
        'DokuHTTPClient'        => DOKU_INC.'inc/HTTPClient.php',
53
        'HTTPClient'            => DOKU_INC.'inc/HTTPClient.php',
54
        'JSON'                  => DOKU_INC.'inc/JSON.php',
55
        'Diff'                  => DOKU_INC.'inc/DifferenceEngine.php',
56
        'UnifiedDiffFormatter'  => DOKU_INC.'inc/DifferenceEngine.php',
57
        'TableDiffFormatter'    => DOKU_INC.'inc/DifferenceEngine.php',
58
        'cache'                 => DOKU_INC.'inc/cache.php',
59
        'cache_parser'          => DOKU_INC.'inc/cache.php',
60
        'cache_instructions'    => DOKU_INC.'inc/cache.php',
61
        'cache_renderer'        => DOKU_INC.'inc/cache.php',
62
        'Doku_Event'            => DOKU_INC.'inc/events.php',
63
        'Doku_Event_Handler'    => DOKU_INC.'inc/events.php',
64
        'EmailAddressValidator' => DOKU_INC.'inc/EmailAddressValidator.php',
65
        'Input'                 => DOKU_INC.'inc/Input.class.php',
66
        'JpegMeta'              => DOKU_INC.'inc/JpegMeta.php',
67
        'SimplePie'             => DOKU_INC.'inc/SimplePie.php',
68
        'FeedParser'            => DOKU_INC.'inc/FeedParser.php',
69
        'IXR_Server'            => DOKU_INC.'inc/IXR_Library.php',
70
        'IXR_Client'            => DOKU_INC.'inc/IXR_Library.php',
71
        'IXR_IntrospectionServer' => DOKU_INC.'inc/IXR_Library.php',
72
        'Doku_Plugin_Controller'=> DOKU_INC.'inc/plugincontroller.class.php',
73
        'Tar'                   => DOKU_INC.'inc/Tar.class.php',
74
        'ZipLib'                => DOKU_INC.'inc/ZipLib.class.php',
75
        'DokuWikiFeedCreator'   => DOKU_INC.'inc/feedcreator.class.php',
76
        'Doku_Parser_Mode'      => DOKU_INC.'inc/parser/parser.php',
77
        'Doku_Parser_Mode_Plugin' => DOKU_INC.'inc/parser/parser.php',
78
        'SafeFN'                => DOKU_INC.'inc/SafeFN.class.php',
79
        'Sitemapper'            => DOKU_INC.'inc/Sitemapper.php',
80
        'PassHash'              => DOKU_INC.'inc/PassHash.class.php',
81
        'Mailer'                => DOKU_INC.'inc/Mailer.class.php',
82
        'RemoteAPI'             => DOKU_INC.'inc/remote.php',
83
        'RemoteAPICore'         => DOKU_INC.'inc/RemoteAPICore.php',
84
        'Subscription'          => DOKU_INC.'inc/subscription.php',
85
        'Crypt_Base'            => DOKU_INC.'inc/phpseclib/Crypt_Base.php',
86
        'Crypt_Rijndael'        => DOKU_INC.'inc/phpseclib/Crypt_Rijndael.php',
87
        'Crypt_AES'             => DOKU_INC.'inc/phpseclib/Crypt_AES.php',
88
        'Crypt_Hash'            => DOKU_INC.'inc/phpseclib/Crypt_Hash.php',
89
        'lessc'                 => DOKU_INC.'inc/lessc.inc.php',
90
91
        'DokuWiki_Action_Plugin' => DOKU_PLUGIN.'action.php',
92
        'DokuWiki_Admin_Plugin'  => DOKU_PLUGIN.'admin.php',
93
        'DokuWiki_Syntax_Plugin' => DOKU_PLUGIN.'syntax.php',
94
        'DokuWiki_Remote_Plugin' => DOKU_PLUGIN.'remote.php',
95
        'DokuWiki_Auth_Plugin'   => DOKU_PLUGIN.'auth.php',
96
97
        'Doku_Renderer'          => DOKU_INC.'inc/parser/renderer.php',
98
        'Doku_Renderer_xhtml'    => DOKU_INC.'inc/parser/xhtml.php',
99
        'Doku_Renderer_code'     => DOKU_INC.'inc/parser/code.php',
100
        'Doku_Renderer_xhtmlsummary' => DOKU_INC.'inc/parser/xhtmlsummary.php',
101
        'Doku_Renderer_metadata' => DOKU_INC.'inc/parser/metadata.php',
102
103
        'DokuCLI'                => DOKU_INC.'inc/cli.php',
104
        'DokuCLI_Options'        => DOKU_INC.'inc/cli.php',
105
        'DokuCLI_Colors'         => DOKU_INC.'inc/cli.php',
106
107
    );
108
109
    if(isset($classes[$name])){
110
        require ($classes[$name]);
111
        return true;
112
    }
113
114
    // namespace to directory conversion
115
    $name = str_replace('\\', '/', $name);
116
117
    // plugin namespace
118
    if(substr($name, 0, 16) == 'dokuwiki/plugin/') {
119
        $name = str_replace('/test/', '/_test/', $name); // no underscore in test namespace
120
        $file = DOKU_PLUGIN . substr($name, 16) . '.php';
121
        if(file_exists($file)) {
122
            require $file;
123
            return true;
124
        }
125
    }
126
127
    // our own namespace
128
    if(substr($name, 0, 9) == 'dokuwiki/') {
129
        require substr($name, 9) . '.php';
130
        return true;
131
    }
132
133
    // Plugin loading
134
    if(preg_match('/^(auth|helper|syntax|action|admin|renderer|remote)_plugin_('.DOKU_PLUGIN_NAME_REGEX.')(?:_([^_]+))?$/',
135
                  $name, $m)) {
136
        // try to load the wanted plugin file
137
        $c = ((count($m) === 4) ? "/{$m[3]}" : '');
138
        $plg = DOKU_PLUGIN . "{$m[2]}/{$m[1]}$c.php";
139
        if(file_exists($plg)){
140
            require $plg;
141
        }
142
        return true;
143
    }
144
    return false;
145
}
146
147