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