| Conditions | 22 |
| Paths | 37 |
| Total Lines | 78 |
| Code Lines | 54 |
| 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 | $array = explode("_", strtolower($classname)); |
||
| 128 | |||
| 129 | if (sizeOf($array) == 3) { |
||
| 130 | |||
| 131 | if ($array[0] == "plugin") { |
||
| 132 | if (file_exists(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php")) { |
||
| 133 | require(ROOT_PATH . "plugins/" . strtolower($array[1]) . "/classes/" . strtolower($array[2]) . ".php"); |
||
| 134 | } else { |
||
| 135 | echo "Could not load plugin-class " . $classname . "!"; |
||
| 136 | } |
||
| 137 | } else { |
||
| 138 | if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 139 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 140 | } else if ($classname == "Smarty") { |
||
| 141 | require("system/libs/smarty/Smarty.class.php"); |
||
| 142 | } else { |
||
| 143 | //echo "Could not (plugin) load class " . $classname . "!"; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | } else if (sizeof($array) == 2) { |
||
| 148 | if ($array[0] == "validator") { |
||
| 149 | if (file_exists(ROOT_PATH . "system/core/validator/" . $array[1] . ".php")) { |
||
| 150 | require(ROOT_PATH . "system/core/validator/" . $array[1] . ".php"); |
||
| 151 | } else { |
||
| 152 | echo "Could not load validator class " . $classname . "!"; |
||
| 153 | } |
||
| 154 | } else if ($array[0] == "datatype") { |
||
| 155 | if (file_exists(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php")) { |
||
| 156 | require(ROOT_PATH . "system/core/datatype/" . $array[1] . ".php"); |
||
| 157 | } else { |
||
| 158 | echo "Could not load datatype class " . $classname . "!"; |
||
| 159 | } |
||
| 160 | } else if (strpos($classname, "Plugin")) { |
||
| 161 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 162 | } else { |
||
| 163 | echo "Could not load class " . $classname . ", unknown prefix '" . $array[0] . "'!"; |
||
| 164 | } |
||
| 165 | } else if (sizeOf($array) == 1) { |
||
| 166 | |||
| 167 | if (file_exists(ROOT_PATH . "system/classes/" . strtolower($classname) . ".php")) { |
||
| 168 | include ROOT_PATH . "system/classes/" . strtolower($classname) . ".php"; |
||
| 169 | } else if (file_exists(ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . "php")) { |
||
| 170 | require ROOT_PATH . "system/libs/smarty/sysplugins/" . strtolower($classname) . ".php"; |
||
| 171 | } else if (strpos($classname, "Plugin")) { |
||
| 172 | //dwoo tries several times to load a class - with and without namespace, so we hide this error message |
||
| 173 | } else { |
||
| 174 | echo "Could not load class " . $classname . " (array size 1)!"; |
||
| 175 | } |
||
| 183 |