| Conditions | 14 |
| Paths | 16 |
| Total Lines | 37 |
| Code Lines | 24 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 21 |
| CRAP Score | 14.129 |
| 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 |
||
| 24 | 46 | public static function validateOptions(array $options): array |
|
| 25 | { |
||
| 26 | 46 | foreach ($options as $option => $value) { |
|
| 27 | switch ($option) { |
||
| 28 | 46 | case Scheduler::OPTION_AT: |
|
| 29 | 46 | if (!is_int($value) && !($value instanceof UTCDateTime)) { |
|
| 30 | throw new InvalidArgumentException('option '.$option.' must be an integer or an instance of '.UTCDateTime::class); |
||
| 31 | } |
||
| 32 | |||
| 33 | 46 | break; |
|
| 34 | 46 | case Scheduler::OPTION_INTERVAL: |
|
| 35 | 46 | case Scheduler::OPTION_RETRY: |
|
| 36 | 45 | case Scheduler::OPTION_RETRY_INTERVAL: |
|
| 37 | 45 | case Scheduler::OPTION_TIMEOUT: |
|
| 38 | 46 | if (!is_int($value)) { |
|
| 39 | 1 | throw new InvalidArgumentException('option '.$option.' must be an integer'); |
|
| 40 | } |
||
| 41 | |||
| 42 | 46 | break; |
|
| 43 | 45 | case Scheduler::OPTION_IGNORE_MAX_CHILDREN: |
|
| 44 | 45 | if (!is_bool($value)) { |
|
| 45 | throw new InvalidArgumentException('option '.$option.' must be a boolean'); |
||
| 46 | } |
||
| 47 | |||
| 48 | 45 | break; |
|
| 49 | 5 | case Scheduler::OPTION_ID: |
|
| 50 | 4 | if (!$value instanceof ObjectId) { |
|
| 51 | 1 | throw new InvalidArgumentException('option '.$option.' must be a an instance of '.ObjectId::class); |
|
| 52 | } |
||
| 53 | |||
| 54 | 3 | break; |
|
| 55 | default: |
||
| 56 | 46 | throw new InvalidArgumentException('invalid option '.$option.' given'); |
|
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | 43 | return $options; |
|
| 61 | } |
||
| 63 |