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