Conditions | 16 |
Paths | 2 |
Total Lines | 55 |
Code Lines | 31 |
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 |
||
117 | private static function set($key, $content) |
||
118 | { |
||
119 | if (false === self::has($key)) { |
||
120 | self::$container[$key] = function ($c) use ($content) { |
||
121 | |||
122 | // if is not a class set the entry value in DIC |
||
123 | if (false === isset($content['class'])) { |
||
124 | return self::getFromEnvOrDICParams($content); |
||
125 | } |
||
126 | |||
127 | // otherwise it's a class, so extract variables |
||
128 | $class = isset($content['class']) ? $content['class'] : null; |
||
129 | $classArguments = isset($content['arguments']) ? $content['arguments'] : null; |
||
130 | $method = isset($content['method']) ? $content['method'] : null; |
||
131 | $methodArguments = isset($content['method_arguments']) ? $content['method_arguments'] : null; |
||
132 | |||
133 | if (false === class_exists($class)) { |
||
134 | return false; |
||
135 | } |
||
136 | |||
137 | // if specified, call a method |
||
138 | if ($method) { |
||
139 | |||
140 | // if specified, call the method with provided arguments |
||
141 | if ($methodArguments) { |
||
142 | try { |
||
143 | return call_user_func_array([$class, $method], self::getArgumentsToInject($c, $methodArguments)); |
||
144 | } catch (\Error $error) { |
||
145 | return false; |
||
146 | } catch (\Exception $exception) { |
||
147 | return false; |
||
148 | } |
||
149 | } |
||
150 | |||
151 | // if not, call the method with no arguments |
||
152 | try { |
||
153 | return self::callClassMethod($class, $method); |
||
154 | } catch (\Error $error) { |
||
155 | return false; |
||
156 | } catch (\Exception $exception) { |
||
157 | return false; |
||
158 | } |
||
159 | } |
||
160 | |||
161 | // if the method is not specified, call the constructor |
||
162 | try { |
||
163 | return new $class(...self::getArgumentsToInject($c, $classArguments)); |
||
164 | } catch (\Error $error) { |
||
165 | return false; |
||
166 | } catch (\Exception $exception) { |
||
167 | return false; |
||
168 | } |
||
169 | }; |
||
170 | |||
171 | return null; |
||
172 | } |
||
275 |