| Conditions | 27 |
| Paths | 77 |
| Total Lines | 103 |
| Code Lines | 67 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 3 | Features | 1 |
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 |
||
| 97 | function cms_autoloader ($classname) { |
||
| 98 | |||
| 99 | ClassLoader::$loadedClasses++; |
||
| 100 | |||
| 101 | if (isset(Classloader::$classlist[$classname])) { |
||
| 102 | require(Classloader::$classlist[$classname]); |
||
| 103 | return null; |
||
| 104 | } |
||
| 105 | |||
| 106 | if (file_exists(ROOT_PATH . "system/core/classes/" . strtolower($classname) . ".php")) { |
||
| 107 | require(ROOT_PATH . "system/core/classes/" . strtolower($classname) . ".php"); |
||
| 108 | return null; |
||
| 109 | } else if (file_exists(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php")) { |
||
| 110 | require(ROOT_PATH . "system/core/exception/" . strtolower($classname) . ".php"); |
||
| 111 | return null; |
||
| 112 | } else if (file_exists(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php")) { |
||
| 113 | require(ROOT_PATH . "system/core/driver/" . strtolower($classname) . ".php"); |
||
| 114 | return null; |
||
| 115 | } |
||
| 116 | |||
| 117 | //check, if class belongs to dwoo template engine |
||
| 118 | if (PHPUtils::startsWith($classname, "Dwoo")) { |
||
| 119 | if (class_exists("DwooAutoloader", true)) { |
||
| 120 | DwooAutoloader::loadClass($classname); |
||
| 121 | return; |
||
| 122 | } else { |
||
| 123 | echo "Could not load Dwoo template engine class " . $classname . "!"; |
||
| 124 | } |
||
| 125 | } |
||
| 126 | |||
| 127 | //check, if we have to use namespace classloading |
||
| 128 | if (PHPUtils::containsStr($classname, "\\")) { |
||
| 129 | //we have to use namespace classloading |
||
| 130 | if (PHPUtils::startsWith($classname, "\\")) { |
||
| 131 | //use normal class loading |
||
| 132 | $classname = substr($classname, 1); |
||
| 133 | } else { |
||
| 134 | $array = explode("_", $classname); |
||
| 135 | |||
| 136 | if ($array[0] === "Plugin") { |
||
| 137 | //load plugin class |
||
| 138 | $path = PLUGIN_PATH . $array[1] . "/" . str_replace("\\", "/", $array[2]) . ".php"; |
||
| 139 | |||
| 140 | if (file_exists($path)) { |
||
| 141 | require($path); |
||
| 142 | } else { |
||
| 143 | $expected_str = (DEBUG_MODE ? " (expected path: " . $path . ")" : ""); |
||
| 144 | echo "Could not load plugin-class with namespace " . $classname . $expected_str . "!"; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | |||
| 148 | return; |
||
| 149 | } |
||
| 150 | } |
||
| 151 | |||
| 152 | $array = explode("_", strtolower($classname)); |
||
| 153 | |||
| 154 | if (sizeOf($array) == 3) { |
||
| 155 | |||
| 156 | if ($array[0] == "plugin") { |
||
| 157 | if (file_exists(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php")) { |
||
| 158 | require(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php"); |
||
| 159 | } else { |
||
| 160 | echo "Could not load plugin-class " . $classname . "!"; |
||
| 161 | } |
||
| 162 | } else { |
||
| 163 | if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 164 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 165 | } else if ($classname == "Smarty") { |
||
| 166 | require("system/libs/smarty/Smarty.class.php"); |
||
| 167 | } else { |
||
| 168 | //echo "Could not (plugin) load class " . $classname . "!"; |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | } else if (sizeof($array) == 2) { |
||
| 173 | if ($array[0] == "validator") { |
||
| 174 | if (file_exists(ROOT_PATH . "system/core/validator/" . $array[1] . ".php")) { |
||
| 175 | require(ROOT_PATH . "system/core/validator/" . $array[1] . ".php"); |
||
| 176 | } else { |
||
| 177 | echo "Could not load validator class " . $classname . "!"; |
||
| 178 | } |
||
| 179 | } else if ($array[0] == "datatype") { |
||
| 180 | if (file_exists(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php")) { |
||
| 181 | require(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php"); |
||
| 182 | } else { |
||
| 183 | echo "Could not load datatype class " . $classname . "!"; |
||
| 184 | } |
||
| 185 | } else if (strpos($classname, "Plugin")) { |
||
| 186 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 187 | } else { |
||
| 188 | echo "Could not load class " . $classname . ", unknown prefix '" . $array[0] . "'!"; |
||
| 189 | } |
||
| 190 | } else if (sizeOf($array) == 1) { |
||
| 191 | |||
| 192 | if (file_exists(ROOT_PATH . "system/classes/" . strtolower($classname) . ".php")) { |
||
| 193 | include ROOT_PATH . "system/classes/" . strtolower($classname) . ".php"; |
||
| 194 | } else if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 195 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 196 | } else if (strpos($classname, "Plugin") !== FALSE) { |
||
| 197 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 198 | } else { |
||
| 199 | echo "Could not load class '" . $classname . "'' (array size 1)!"; |
||
| 200 | } |
||
| 208 |