| 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 | public 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 specified, call a method |
||
| 134 | if ($method) { |
||
| 135 | |||
| 136 | // if specified, call the method with provided arguments |
||
| 137 | if ($methodArguments) { |
||
| 138 | try { |
||
| 139 | return call_user_func_array([$class, $method], self::getArgumentsToInject($c, $methodArguments)); |
||
| 140 | } catch (\Error $error) { |
||
| 141 | return false; |
||
| 142 | } catch (\Exception $exception) { |
||
| 143 | return false; |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 147 | // if not, call the method with no arguments |
||
| 148 | try { |
||
| 149 | return call_user_func([$class, $method]); |
||
| 150 | } catch (\Error $error) { |
||
| 151 | return false; |
||
| 152 | } catch (\Exception $exception) { |
||
| 153 | return false; |
||
| 154 | } |
||
| 155 | } |
||
| 156 | |||
| 157 | if (false === class_exists($class)) { |
||
| 158 | return false; |
||
| 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 | } |
||
| 253 |