| Conditions | 29 |
| Paths | 79 |
| Total Lines | 122 |
| Code Lines | 77 |
| 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 |
||
| 112 | function cms_autoloader ($classname) { |
||
| 113 | |||
| 114 | ClassLoader::$loadedClasses++; |
||
| 115 | |||
| 116 | if (isset(Classloader::$classlist[$classname])) { |
||
| 117 | require(Classloader::$classlist[$classname]); |
||
| 118 | return null; |
||
| 119 | } |
||
| 120 | |||
| 121 | if (file_exists(ROOT_PATH . "system/core/classes/" . strtolower($classname) . ".php")) { |
||
| 122 | require(ROOT_PATH . "system/core/classes/" . strtolower($classname) . ".php"); |
||
| 123 | return null; |
||
| 124 | } else if (file_exists(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php")) { |
||
| 125 | require(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php"); |
||
| 126 | return null; |
||
| 127 | } else if (file_exists(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php")) { |
||
| 128 | require(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php"); |
||
| 129 | return null; |
||
| 130 | } |
||
| 131 | |||
| 132 | //check, if class belongs to dwoo template engine |
||
| 133 | if (PHPUtils::startsWith($classname, "Dwoo")) { |
||
| 134 | if (class_exists("DwooAutoloader", true)) { |
||
| 135 | DwooAutoloader::loadClass($classname); |
||
| 136 | return; |
||
| 137 | } else { |
||
| 138 | echo "Could not load Dwoo template engine class " . $classname . "!"; |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 142 | //check, if we have to use namespace classloading |
||
| 143 | if (PHPUtils::containsStr($classname, "\\")) { |
||
| 144 | //we have to use namespace classloading |
||
| 145 | if (PHPUtils::startsWith($classname, "\\")) { |
||
| 146 | //use normal class loading |
||
| 147 | $classname = substr($classname, 1); |
||
| 148 | } else { |
||
| 149 | $array = explode("\\", strtolower($classname)); |
||
| 150 | |||
| 151 | if ($array[0] === "plugin") { |
||
| 152 | $array1 = array(); |
||
| 153 | |||
| 154 | for ($i = 2; $i < count($array); $i++) { |
||
| 155 | $array1[] = $array[$i]; |
||
| 156 | } |
||
| 157 | |||
| 158 | $file_name = implode("/", $array1); |
||
| 159 | |||
| 160 | //load plugin class |
||
| 161 | $path = PLUGIN_PATH . $array[1] . "/classes/" . $file_name . ".php"; |
||
| 162 | |||
| 163 | if (file_exists($path)) { |
||
| 164 | require($path); |
||
| 165 | } else { |
||
| 166 | $expected_str = (DEBUG_MODE ? " (expected path: " . $path . ")" : ""); |
||
| 167 | echo "Could not load plugin-class with namespace " . $classname . $expected_str . "!"; |
||
| 168 | } |
||
| 169 | } else { |
||
| 170 | //check, if there is a classloader for this prefix |
||
| 171 | if (isset(ClassLoader::$namespace_autoloader[$array[0]])) { |
||
| 172 | //get function |
||
| 173 | $func = ClassLoader::$namespace_autoloader[$array[0]]; |
||
| 174 | |||
| 175 | //call func |
||
| 176 | $func($classname); |
||
| 177 | } else { |
||
| 178 | throw new IllegalStateException("Cannot load namespace class '" . $classname . "' with unknown prefix '" . $array[0] . "'!"); |
||
| 179 | } |
||
| 180 | } |
||
| 181 | |||
| 182 | return; |
||
| 183 | } |
||
| 184 | } |
||
| 185 | |||
| 186 | $array = explode("_", strtolower($classname)); |
||
| 187 | |||
| 188 | if (sizeOf($array) == 3) { |
||
| 189 | |||
| 190 | if ($array[0] == "plugin") { |
||
| 191 | if (file_exists(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php")) { |
||
| 192 | require(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php"); |
||
| 193 | } else { |
||
| 194 | echo "Could not load plugin-class " . $classname . "!"; |
||
| 195 | } |
||
| 196 | } else { |
||
| 197 | if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 198 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 199 | } else if ($classname == "Smarty") { |
||
| 200 | require("system/libs/smarty/Smarty.class.php"); |
||
| 201 | } else { |
||
| 202 | //echo "Could not (plugin) load class " . $classname . "!"; |
||
| 203 | } |
||
| 204 | } |
||
| 205 | |||
| 206 | } else if (sizeof($array) == 2) { |
||
| 207 | if ($array[0] == "validator") { |
||
| 208 | if (file_exists(ROOT_PATH . "system/core/validator/" . $array[1] . ".php")) { |
||
| 209 | require(ROOT_PATH . "system/core/validator/" . $array[1] . ".php"); |
||
| 210 | } else { |
||
| 211 | echo "Could not load validator class " . $classname . "!"; |
||
| 212 | } |
||
| 213 | } else if ($array[0] == "datatype") { |
||
| 214 | if (file_exists(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php")) { |
||
| 215 | require(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php"); |
||
| 216 | } else { |
||
| 217 | echo "Could not load datatype class " . $classname . "!"; |
||
| 218 | } |
||
| 219 | } else if (strpos($classname, "Plugin")) { |
||
| 220 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 221 | } else { |
||
| 222 | echo "Could not load class " . $classname . ", unknown prefix '" . $array[0] . "'!"; |
||
| 223 | } |
||
| 224 | } else if (sizeOf($array) == 1) { |
||
| 225 | |||
| 226 | if (file_exists(ROOT_PATH . "system/classes/" . strtolower($classname) . ".php")) { |
||
| 227 | include ROOT_PATH . "system/classes/" . strtolower($classname) . ".php"; |
||
| 228 | } else if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 229 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 230 | } else if (strpos($classname, "Plugin") !== FALSE) { |
||
| 231 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 232 | } else { |
||
| 233 | echo "Could not load class '" . $classname . "'' (array size 1)!"; |
||
| 234 | } |
||
| 242 |