| Conditions | 14 |
| Paths | 7 |
| Total Lines | 20 |
| Code Lines | 12 |
| 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 |
||
| 56 | private function isValidConfigs(array $configs): void |
||
| 57 | { |
||
| 58 | $allowedConfigKeys = $this->getAllowedConfigKeys(); |
||
| 59 | if (!empty($configs)) { |
||
| 60 | foreach ($configs as $key => $value) { |
||
| 61 | if (!\in_array($key, $allowedConfigKeys, true)) { |
||
| 62 | throw new \InvalidArgumentException($key . ' is not a valid key. $configs must only contain ' . implode(', ', |
||
| 63 | $allowedConfigKeys)); |
||
| 64 | } |
||
| 65 | |||
| 66 | if (($key === NlpInterface::CONFIG_KEY_NLP_ENABLED || $key === NlpInterface::CONFIG_KEY_VERBOSE) && !\is_bool($value)) { |
||
| 67 | throw new \InvalidArgumentException($key . ' must be a boolean'); |
||
| 68 | } |
||
| 69 | |||
| 70 | if (($key === NlpInterface::CONFIG_KEY_CUSTOM_TOKEN || $key === NlpInterface::CONFIG_KEY_MODEL) && !\is_string($value)) { |
||
| 71 | throw new \InvalidArgumentException($key . ' must be a string'); |
||
| 72 | } |
||
| 73 | |||
| 74 | if ($key === NlpInterface::CONFIG_KEY_N_BEST && (!\is_int($value) || $value < 1 || $value > 8)) { |
||
| 75 | throw new \InvalidArgumentException($key . ' must be an integer between 1 and 8'); |
||
| 76 | } |
||
| 95 |