| Conditions | 12 |
| Paths | 98 |
| Total Lines | 46 |
| 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 |
||
| 16 | public function validate(Config $config) |
||
| 17 | { |
||
| 18 | // required |
||
| 19 | if (!$config->has('files')) { |
||
| 20 | throw new ConfigException('Directory to parse is missing or incorrect'); |
||
| 21 | } |
||
| 22 | foreach ($config->get('files') as $dir) { |
||
|
|
|||
| 23 | if (!file_exists($dir)) { |
||
| 24 | throw new ConfigException(sprintf('Directory %s does not exist', $dir)); |
||
| 25 | } |
||
| 26 | } |
||
| 27 | |||
| 28 | // extensions |
||
| 29 | if (!$config->has('extensions')) { |
||
| 30 | $config->set('extensions', 'php,inc'); |
||
| 31 | } |
||
| 32 | $config->set('extensions', explode(',', $config->get('extensions'))); |
||
| 33 | |||
| 34 | // excluded directories |
||
| 35 | if (!$config->has('exclude')) { |
||
| 36 | $config->set('exclude', 'vendor,test,Test,tests,Tests,testing,Testing,bower_components,node_modules,cache,spec'); |
||
| 37 | } |
||
| 38 | $config->set('exclude', array_filter(explode(',', $config->get('exclude')))); |
||
| 39 | |||
| 40 | // groups by regex |
||
| 41 | if (!$config->has('groups')) { |
||
| 42 | $config->set('groups', [['name' => 'all', 'match' => '!.*!']]); |
||
| 43 | } |
||
| 44 | $groupsRaw = $config->get('groups'); |
||
| 45 | |||
| 46 | $groups = []; |
||
| 47 | $config->set('groups', []); |
||
| 48 | foreach ($groupsRaw as $groupRaw) { |
||
| 49 | $groups[] = new Group($groupRaw['name'], $groupRaw['match']); |
||
| 50 | } |
||
| 51 | $config->set('groups', $groups); |
||
| 52 | |||
| 53 | // parameters with values |
||
| 54 | $keys = ['report-html', 'report-csv', 'report-violation', 'report-json', 'extensions', 'config']; |
||
| 55 | foreach ($keys as $key) { |
||
| 56 | $value = $config->get($key); |
||
| 57 | if ($config->has($key) && empty($value) || true === $value) { |
||
| 58 | throw new ConfigException(sprintf('%s option requires a value', $key)); |
||
| 59 | } |
||
| 60 | } |
||
| 61 | } |
||
| 62 | |||
| 106 |