| Conditions | 10 |
| Paths | 8 |
| Total Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 | public static function validate(array $resource): array |
||
| 22 | { |
||
| 23 | $defaults = [ |
||
| 24 | 'options' => [ |
||
| 25 | 'identifier' => '$dn$', |
||
| 26 | ], |
||
| 27 | 'resource' => [ |
||
| 28 | 'request_options' => [], |
||
| 29 | 'auth' => [ |
||
| 30 | 'username' => null, |
||
| 31 | 'password' => null, |
||
| 32 | ], |
||
| 33 | ], |
||
| 34 | ]; |
||
| 35 | |||
| 36 | if (!isset($resource['resource']['base_uri']) || !is_string($resource['resource']['base_uri'])) { |
||
| 37 | throw new InvalidArgumentException('resource.base_uri is required and must be a valid ucs url [string]'); |
||
| 38 | } |
||
| 39 | |||
| 40 | if (!isset($resource['resource']['flavor']) || !is_string($resource['resource']['flavor'])) { |
||
| 41 | throw new InvalidArgumentException('resource.flavor is required and must be a valid ucs flavor'); |
||
| 42 | } |
||
| 43 | |||
| 44 | foreach ($resource['resource'] as $key => $value) { |
||
| 45 | switch ($key) { |
||
| 46 | case 'request_options': |
||
| 47 | case 'flavor': |
||
| 48 | case 'auth': |
||
| 49 | case 'base_uri': |
||
| 50 | break; |
||
| 51 | default: |
||
| 52 | throw new InvalidArgumentException("unknown option resource.$key provided"); |
||
| 53 | } |
||
| 54 | } |
||
| 55 | |||
| 56 | return array_replace_recursive($defaults, $resource); |
||
| 57 | } |
||
| 58 | } |
||
| 59 |