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