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