| Conditions | 15 | 
| Paths | 15 | 
| Total Lines | 58 | 
| Code Lines | 34 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Tests | 37 | 
| CRAP Score | 15 | 
| Changes | 5 | ||
| 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 | ||
| 20 | 12 | private function ensure($types, array $args) | |
| 21 |     { | ||
| 22 | 12 |         if (!is_string($types)) { | |
| 23 | 1 |             throw new InvalidArgumentException('Type list must be of type string'); | |
| 24 | } | ||
| 25 | |||
| 26 | 11 | $cnt = count($args); | |
| 27 | |||
| 28 | 11 |         if (strlen($types) !== $cnt) { | |
| 29 | 1 |             throw new InvalidArgumentException('Type list length does not match argument count'); | |
| 30 | } | ||
| 31 | |||
| 32 | 10 | $i = 0; | |
| 33 | |||
| 34 | 10 |         foreach ($args as $arg) { | |
| 35 | 10 |             switch ($types[$i]) { | |
| 36 | 10 | case 'b': | |
| 37 | 4 |                     if (!is_bool($arg)) { | |
| 38 | 1 |                         throw new InvalidArgumentException('bool expected'); | |
| 39 | } | ||
| 40 | 3 | break; | |
| 41 | |||
| 42 | 9 | case 'f': | |
| 43 | 4 |                     if (!is_float($arg)) { | |
| 44 | 1 |                         throw new InvalidArgumentException('float expected'); | |
| 45 | } | ||
| 46 | 3 | break; | |
| 47 | |||
| 48 | 8 | case 'i': | |
| 49 | 4 |                     if (!is_int($arg)) { | |
| 50 | 1 |                         throw new InvalidArgumentException('int expected'); | |
| 51 | } | ||
| 52 | 3 | break; | |
| 53 | |||
| 54 | 7 | case 'r': | |
| 55 | 2 |                     if (!is_resource($arg)) { | |
| 56 | 1 |                         throw new InvalidArgumentException('resource expected'); | |
| 57 | } | ||
| 58 | 1 | break; | |
| 59 | |||
| 60 | 5 | case 's': | |
| 61 | 4 |                     if (!is_string($arg)) { | |
| 62 | 1 |                         throw new InvalidArgumentException('string expected'); | |
| 63 | } | ||
| 64 | 3 | break; | |
| 65 | |||
| 66 | 4 | case '-': | |
| 67 | /* skip */ | ||
| 68 | 3 | break; | |
| 69 | |||
| 70 | 1 | default: | |
| 71 | 1 |                     throw new InvalidArgumentException('Unknown type at offset ' . $i . '. One of [bfirs-] expected'); | |
| 72 | // no break | ||
| 73 | 5 | } | |
| 74 | |||
| 75 | 4 | $i++; | |
| 76 | 4 | } | |
| 77 | 4 | } | |
| 78 | } | ||
| 79 |