| Conditions | 10 |
| Paths | 7 |
| Total Lines | 28 |
| Code Lines | 14 |
| 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 |
||
| 53 | public static function normalize($config, string $id = null): DefinitionInterface |
||
| 54 | { |
||
| 55 | if ($config instanceof DefinitionInterface) { |
||
| 56 | return $config; |
||
| 57 | } |
||
| 58 | |||
| 59 | if (\is_string($config)) { |
||
| 60 | return Reference::to($config); |
||
| 61 | } |
||
| 62 | |||
| 63 | if (\is_array($config) |
||
| 64 | && !(isset($config[0], $config[1]) && count($config) === 2) |
||
| 65 | ) { |
||
| 66 | if (empty($config['__class']) && $id) { |
||
| 67 | $config['__class'] = $id; |
||
| 68 | } |
||
| 69 | return new ArrayDefinition($config); |
||
| 70 | } |
||
| 71 | |||
| 72 | if (\is_callable($config)) { |
||
| 73 | return new CallableDefinition($config); |
||
| 74 | } |
||
| 75 | |||
| 76 | if (\is_object($config)) { |
||
| 77 | return new ValueDefinition($config); |
||
| 78 | } |
||
| 79 | |||
| 80 | throw new InvalidConfigException('Invalid definition:' . var_export($config, true)); |
||
| 81 | } |
||
| 83 |