| Conditions | 12 |
| Paths | 88 |
| Total Lines | 31 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 22 | public function denormalize($data, $type, $format = null, array $context = []) |
||
| 23 | { |
||
| 24 | $internalType = $type; |
||
| 25 | if ($type === CarbonInterface::class) { |
||
| 26 | $internalType = DateTimeInterface::class; |
||
| 27 | } |
||
| 28 | if ($type === Carbon::class) { |
||
| 29 | $internalType = DateTime::class; |
||
| 30 | } |
||
| 31 | if ($type === CarbonImmutable::class) { |
||
| 32 | $internalType = DateTimeImmutable::class; |
||
| 33 | } |
||
| 34 | $result = parent::denormalize($data, $internalType, $format, $context); |
||
| 35 | switch($type) { |
||
| 36 | case Carbon::class: |
||
| 37 | case DateTime::class: |
||
| 38 | return Carbon::make($result); |
||
| 39 | case DateTimeInterface::class: |
||
| 40 | case CarbonInterface::class: |
||
| 41 | if (class_exists(CarbonImmutable::class)) { |
||
| 42 | return CarbonImmutable::make($result); |
||
| 43 | } |
||
| 44 | return Carbon::make($result); |
||
| 45 | case CarbonImmutable::class: |
||
| 46 | case DateTimeImmutable::class: |
||
| 47 | if (class_exists(CarbonImmutable::class)) { |
||
| 48 | return CarbonImmutable::make($result); |
||
| 49 | } |
||
| 50 | return $result; |
||
| 51 | } |
||
| 52 | return $result; |
||
| 53 | } |
||
| 71 |