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