| Conditions | 12 |
| Paths | 12 |
| Total Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 38 | public static function convert($value, $type, $dateFormat = null) { |
||
| 39 | switch ($type) { |
||
| 40 | case self::ARGUMENT_BOOLEAN: |
||
| 41 | return BooleanHelper::parseString($value); |
||
| 42 | case self::ARGUMENT_DATE: |
||
| 43 | if (null === $dateFormat) { |
||
| 44 | throw new NullPointerException("The date format is null"); |
||
| 45 | } |
||
| 46 | $datetime = DateTime::createFromFormat($dateFormat, $value); |
||
| 47 | if (false === $datetime) { |
||
| 48 | throw new DateArgumentException($value); |
||
| 49 | } |
||
| 50 | return $datetime; |
||
| 51 | case self::ARGUMENT_DOUBLE: |
||
| 52 | return DoubleHelper::parseString($value); |
||
| 53 | case self::ARGUMENT_FLOAT: |
||
| 54 | return FloatHelper::parseString($value); |
||
| 55 | case self::ARGUMENT_INTEGER: |
||
| 56 | return IntegerHelper::parseString($value); |
||
| 57 | case self::ARGUMENT_STRING: |
||
| 58 | return $value; |
||
| 59 | case self::ARGUMENT_TIMESTAMP: |
||
| 60 | if (null === $dateFormat) { |
||
| 61 | throw new NullPointerException("The datetime format is null"); |
||
| 62 | } |
||
| 63 | $datetime = DateTime::createFromFormat($dateFormat, $value); |
||
| 64 | if (false === $datetime) { |
||
| 65 | throw new TimestampArgumentException($value); |
||
| 66 | } |
||
| 67 | return $datetime; |
||
| 68 | default: |
||
| 69 | throw new IllegalArgumentException("The type \"" . $type . "\" is not implemented"); |
||
| 70 | } |
||
| 71 | } |
||
| 72 | |||
| 122 |