| Conditions | 17 |
| Paths | 9 |
| Total Lines | 32 |
| Code Lines | 16 |
| 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 |
||
| 21 | protected function validate($config): void |
||
| 22 | { |
||
| 23 | parent::validate($config); |
||
| 24 | |||
| 25 | // Check boolean parameters |
||
| 26 | if (! isset($config['overwrite']) || ! is_bool($config['overwrite'])) { |
||
| 27 | throw new InvalidConfigException('"overwrite" parameter must be set as a boolean.'); |
||
| 28 | } |
||
| 29 | |||
| 30 | if (! isset($config['auto']) || ! is_bool($config['auto'])) { |
||
| 31 | throw new InvalidConfigException('"auto" parameter must be set as a boolean.'); |
||
| 32 | } |
||
| 33 | if (! isset($config['ignore']) || ! is_bool($config['ignore'])) { |
||
| 34 | throw new InvalidConfigException('"ignore" parameter must be set as a boolean.'); |
||
| 35 | } |
||
| 36 | |||
| 37 | // Check string parameters |
||
| 38 | if (! isset($config['include']) || ! is_string($config['include'])) { |
||
| 39 | throw new InvalidConfigException('"include" parameter must be set as a string.'); |
||
| 40 | } |
||
| 41 | if (! isset($config['exclude']) || ! is_string($config['exclude'])) { |
||
| 42 | throw new InvalidConfigException('"exclude" parameter must be set as a string.'); |
||
| 43 | } |
||
| 44 | |||
| 45 | // Check that dirs exists |
||
| 46 | if (! isset($config['dirs']) || ! is_array($config['dirs']) || count($config['dirs']) < 1) { |
||
| 47 | throw new InvalidConfigException('"dirs" parameter is not an array or does not contains elements.'); |
||
| 48 | } |
||
| 49 | // Validate dirs |
||
| 50 | foreach ($config['dirs'] as $srcDir => $testsDir) { |
||
| 51 | if (! is_string($srcDir) || ! is_string($testsDir)) { |
||
| 52 | throw new InvalidConfigException('Some directories in "dirs" parameter are not strings.'); |
||
| 53 | } |
||
| 97 |