Conditions | 11 |
Paths | 9 |
Total Lines | 38 |
Code Lines | 20 |
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 |
||
57 | public static function normalize($definition, string $id = null, array $constructorArguments = [], array $allowedMeta = []): DefinitionInterface |
||
58 | { |
||
59 | if ($definition instanceof DefinitionInterface) { |
||
60 | return $definition; |
||
61 | } |
||
62 | |||
63 | if (is_string($definition)) { |
||
64 | if (empty($definition)) { |
||
65 | throw new InvalidConfigException('Invalid definition: empty string.'); |
||
66 | } |
||
67 | if ($id === $definition || (!empty($constructorArguments) && class_exists($definition))) { |
||
68 | /** @psalm-var class-string $definition */ |
||
69 | return new ArrayDefinition([ |
||
70 | ArrayDefinition::CLASS_NAME => $definition, |
||
71 | ArrayDefinition::CONSTRUCTOR => $constructorArguments, |
||
72 | ]); |
||
73 | } |
||
74 | return Reference::to($definition); |
||
75 | } |
||
76 | |||
77 | if (is_callable($definition, true)) { |
||
78 | return new CallableDefinition($definition); |
||
79 | } |
||
80 | |||
81 | if (is_array($definition)) { |
||
82 | $config = $definition; |
||
83 | if (!array_key_exists(ArrayDefinition::CLASS_NAME, $config)) { |
||
84 | $config[ArrayDefinition::CLASS_NAME] = $id; |
||
85 | } |
||
86 | /** @psalm-suppress ArgumentTypeCoercion */ |
||
87 | return new ArrayDefinition($config, $allowedMeta); |
||
88 | } |
||
89 | |||
90 | if (is_object($definition)) { |
||
91 | return new ValueDefinition($definition); |
||
92 | } |
||
93 | |||
94 | throw new InvalidConfigException('Invalid definition:' . var_export($definition, true)); |
||
95 | } |
||
189 |