Conditions | 12 |
Paths | 9 |
Total Lines | 37 |
Code Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
28 | function autoLoad($class, $throwException = true) |
||
29 | { |
||
30 | if (class_exists($class, false)) { |
||
31 | return true; |
||
32 | } |
||
33 | |||
34 | global $rootPath; |
||
35 | $file = $rootPath . str_replace('\\', '/', $class) . ".php"; |
||
36 | $debug_backtrace = debug_backtrace(); |
||
37 | |||
38 | if (file_exists($file)) { |
||
39 | require_once($file); |
||
40 | if ($throwException) { |
||
41 | if (class_exists($class, false) === false && interface_exists($class, false) === false) { |
||
42 | throw new \Exception('Could not load class "' . $class . '" in file ' . $file); |
||
43 | } else { |
||
44 | return true; |
||
45 | } |
||
46 | } |
||
47 | return class_exists($class, false) || interface_exists($class, false); |
||
48 | } else { |
||
49 | if (isset($debug_backtrace[2]) && isset($debug_backtrace[2]['file']) && isset($debug_backtrace[2]['line'])) { |
||
50 | if ($throwException) { |
||
51 | errorHandler(0, 'Could not load class \'' . $class . '\' in file ' . $rootPath . $file, $debug_backtrace[2]['file'], $debug_backtrace[2]['line']); |
||
52 | } else { |
||
53 | return false; |
||
54 | } |
||
55 | } else { |
||
56 | if ($throwException) { |
||
57 | throw new \Exception('Could not load class "' . $class . '" in file ' . $file . "\n" . 'Called from unknown origin.'); |
||
58 | } else { |
||
59 | return false; |
||
60 | } |
||
61 | } |
||
62 | } |
||
63 | return false; |
||
64 | } |