| Conditions | 14 |
| Paths | 41 |
| Total Lines | 45 |
| Code Lines | 24 |
| 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 /** MicroInjector */ |
||
| 103 | private function loadInjection($name) |
||
| 104 | { |
||
| 105 | $options = self::$CONFIG['components'][$name]; |
||
| 106 | |||
| 107 | if (empty($options['class']) || !class_exists($options['class'])) { |
||
| 108 | return false; |
||
| 109 | } |
||
| 110 | |||
| 111 | $className = $options['class']; |
||
| 112 | |||
| 113 | $options['arguments'] = !empty($options['arguments']) ? $this->buildParams($options['arguments']) : null; |
||
| 114 | $options['property'] = !empty($options['property']) ? $this->buildParams($options['property']) : null; |
||
| 115 | $options['calls'] = !empty($options['calls']) ? $this->buildCalls($options['calls']) : null; |
||
| 116 | |||
| 117 | /** Depends via construction */ |
||
| 118 | self::$INJECTS[$name] = $this->makeObject($className, $options['arguments']); |
||
| 119 | if (!self::$INJECTS[$name]) { |
||
| 120 | return false; |
||
| 121 | } |
||
| 122 | |||
| 123 | /** Depends via property */ |
||
| 124 | if (!empty($options['property'])) { // load properties |
||
| 125 | foreach ($options['property'] as $property => $value) { |
||
| 126 | if (property_exists(self::$INJECTS[$name], $property)) { |
||
| 127 | self::$INJECTS[$name]->$property = $value; |
||
| 128 | } |
||
| 129 | } |
||
| 130 | } |
||
| 131 | |||
| 132 | /** Depends via calls */ |
||
| 133 | if (!empty($options['calls'])) { // run methods |
||
| 134 | foreach ($options['calls'] as $method => $arguments) { |
||
| 135 | if (method_exists(self::$INJECTS[$name], $method)) { |
||
| 136 | $reflectionMethod = new \ReflectionMethod($className, $method); |
||
| 137 | if ($reflectionMethod->getNumberOfParameters() === 0) { |
||
| 138 | self::$INJECTS[$name]->$method(); |
||
| 139 | } else { |
||
| 140 | call_user_func_array([self::$INJECTS[$name], $method], $arguments); |
||
| 141 | } |
||
| 142 | } |
||
| 143 | } |
||
| 144 | } |
||
| 145 | |||
| 146 | return self::$INJECTS[$name]; |
||
| 147 | } |
||
| 148 | |||
| 227 | } |