| Conditions | 14 |
| Paths | 1544 |
| Total Lines | 51 |
| Code Lines | 28 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 43 | private static function enrichParameters(Parameter $parameter, array $config): void |
||
| 44 | { |
||
| 45 | $parameter->setRawStructure($config); |
||
| 46 | |||
| 47 | if (array_key_exists('name', $config)) { |
||
| 48 | $parameter->setName($config['name']); |
||
| 49 | } |
||
| 50 | |||
| 51 | if (array_key_exists('forceDefault', $config)) { |
||
| 52 | $parameter->setForceDefault($config['forceDefault']); |
||
| 53 | } |
||
| 54 | |||
| 55 | if (array_key_exists('description', $config)) { |
||
| 56 | $parameter->setDescription($config['description']); |
||
| 57 | } |
||
| 58 | |||
| 59 | if (array_key_exists('default', $config)) { |
||
| 60 | if (!is_string($config['default']) && !is_int($config['default'])) { |
||
| 61 | throw new \RuntimeException('The default value must be a string or an integer (name: ' . $config['name'] . '). ' . ucfirst(gettype($config['default'])) . ' with value ' . json_encode($config['default']) . ' given.'); |
||
| 62 | } |
||
| 63 | $defaultValue = self::getDefaultValue($config['default']); |
||
| 64 | if ($defaultValue !== '') { |
||
| 65 | $parameter->setDefaultValue($defaultValue); |
||
| 66 | } |
||
| 67 | } |
||
| 68 | |||
| 69 | if (array_key_exists(self::FIELD_CONSTRAINTS, $config)) { |
||
| 70 | $constraints = self::getConstraints($config[self::FIELD_CONSTRAINTS]); |
||
| 71 | $parameter->setConstraints($constraints); |
||
| 72 | } |
||
| 73 | |||
| 74 | if (!array_key_exists('enum-allow-custom', $config)) { |
||
| 75 | $enumAllowCustom = false; |
||
| 76 | } else { |
||
| 77 | $enumAllowCustom = $config['enum-allow-custom']; |
||
| 78 | } |
||
| 79 | |||
| 80 | if (array_key_exists('enum', $config)) { |
||
| 81 | $parameter->setValues($config['enum'], $enumAllowCustom); |
||
| 82 | } |
||
| 83 | |||
| 84 | if (array_key_exists('prefix', $config)) { |
||
| 85 | $parameter->setPrefix($config['prefix']); |
||
| 86 | } |
||
| 87 | |||
| 88 | if (array_key_exists('suffix', $config)) { |
||
| 89 | $parameter->setSuffix($config['suffix']); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (array_key_exists('optional', $config)) { |
||
| 93 | $parameter->setOptional((bool)$config['optional']); |
||
| 94 | } |
||
| 144 |