| Conditions | 10 |
| Paths | 9 |
| Total Lines | 65 |
| 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 |
||
| 54 | public static function getHooks($classpath, $namespace, $classname = null, $extends = null, $method = null) { |
||
| 55 | |||
| 56 | // |
||
| 57 | $hooks = []; |
||
| 58 | |||
| 59 | // Get the filenames. |
||
| 60 | $filenames = FileHelper::getFileNames($classpath, ".php"); |
||
| 61 | |||
| 62 | // Handle each filenames. |
||
| 63 | foreach ($filenames as $filename) { |
||
| 64 | |||
| 65 | // Check the class name. |
||
| 66 | if (null !== $classname && 0 === preg_match($classname, $filename)) { |
||
| 67 | continue; |
||
| 68 | } |
||
| 69 | |||
| 70 | // Import the class. |
||
| 71 | try { |
||
| 72 | require_once $classpath . "/" . $filename; |
||
| 73 | } catch (Error $ex) { |
||
|
|
|||
| 74 | throw new SyntaxErrorException($classpath . "/" . $filename); |
||
| 75 | } |
||
| 76 | |||
| 77 | // Init. the complete class name. |
||
| 78 | $completeClassname = $namespace . basename($filename, ".php"); |
||
| 79 | |||
| 80 | try { |
||
| 81 | $rc = new ReflectionClass($completeClassname); |
||
| 82 | } catch (Exception $ex) { |
||
| 83 | throw new ClassNotFoundException($completeClassname, $ex); |
||
| 84 | } |
||
| 85 | |||
| 86 | // Check the extends. |
||
| 87 | if (false === (null === $extends || true === $rc->isSubclassOf($extends))) { |
||
| 88 | continue; |
||
| 89 | } |
||
| 90 | |||
| 91 | // Initialize the hook. |
||
| 92 | $hook = []; |
||
| 93 | |||
| 94 | $hook["classpath"] = $classpath; |
||
| 95 | $hook["namespace"] = $namespace; |
||
| 96 | $hook["filename"] = $filename; |
||
| 97 | $hook["class"] = $rc; |
||
| 98 | $hook["method"] = null; |
||
| 99 | |||
| 100 | $hooks[] = $hook; |
||
| 101 | |||
| 102 | // Check the method. |
||
| 103 | if (null === $method) { |
||
| 104 | continue; |
||
| 105 | } |
||
| 106 | |||
| 107 | try { |
||
| 108 | $rm = $rc->getMethod($method); |
||
| 109 | |||
| 110 | $hooks[count($hooks) - 1]["method"] = $rm; |
||
| 111 | } catch (ReflectionException $ex) { |
||
| 112 | throw new MethodNotFoundException($method, $ex); |
||
| 113 | } |
||
| 114 | } |
||
| 115 | |||
| 116 | // Returns the hooks. |
||
| 117 | return $hooks; |
||
| 118 | } |
||
| 119 | |||
| 180 |