| Conditions | 23 |
| Paths | 23 |
| Total Lines | 62 |
| Code Lines | 49 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | 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 |
||
| 43 | if (false === is_array($value)) { |
||
| 44 | throw new ArrayArgumentException($value); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Determines if a value is a boolean. |
||
| 50 | * |
||
| 51 | * @param mixed $value The value. |
||
| 52 | * @throws BooleanArgumentException Throws a Boolean argument exception if the value is not of expected type. |
||
| 53 | */ |
||
| 54 | private static function isBoolean($value) { |
||
| 55 | if (false === is_bool($value)) { |
||
| 56 | throw new BooleanArgumentException($value); |
||
| 57 | } |
||
| 58 | } |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Determines if a value is a date. |
||
| 62 | * |
||
| 63 | * @param mixed $value The value. |
||
| 64 | * @throws DateArgumentException Throws a Date argument exception if the value is not of expected type. |
||
| 65 | */ |
||
| 66 | private static function isDate($value) { |
||
| 67 | if (false === strtotime($value)) { |
||
| 68 | throw new DateArgumentException($value); |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Determines if a value is a double. |
||
| 74 | * |
||
| 75 | * @param mixed $value The value. |
||
| 76 | * @throws DoubleArgumentException Throws a Double argument exception if the value is not of expected type. |
||
| 77 | */ |
||
| 78 | private static function isDouble($value) { |
||
| 79 | if (false === is_double($value)) { |
||
| 80 | throw new DoubleArgumentException($value); |
||
| 81 | } |
||
| 82 | } |
||
| 83 | |||
| 84 | /** |
||
| 85 | * Determines if a value is a float. |
||
| 86 | * |
||
| 87 | * @param mixed $value The value. |
||
| 88 | * @throws FloatArgumentException Throws a Float argument exception if the value is not of expected type. |
||
| 89 | */ |
||
| 90 | private static function isFloat($value) { |
||
| 91 | if (false === is_float($value)) { |
||
| 92 | throw new FloatArgumentException($value); |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | /** |
||
| 97 | * Determines if a value is an integer. |
||
| 98 | * |
||
| 99 | * @param mixed $value The value. |
||
| 100 | * @throws IntegerArgumentException Throws a Integer argument exception if the value is not of expected type. |
||
| 101 | */ |
||
| 102 | private static function isInteger($value) { |
||
| 103 | if (false === is_integer($value)) { |
||
| 104 | throw new IntegerArgumentException($value); |
||
| 105 | } |
||
| 217 |