| Conditions | 12 |
| Paths | 4 |
| Total Lines | 41 |
| Code Lines | 31 |
| 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 |
||
| 35 | public function denormalize($data, $class, $format = null, array $context = []) |
||
| 36 | { |
||
| 37 | if (is_string($data)) { |
||
| 38 | $data = json_decode($data, true); |
||
| 39 | } |
||
| 40 | |||
| 41 | /** @var ListItemContact $item */ |
||
| 42 | $item = new $class(); |
||
| 43 | |||
| 44 | if ($data) { |
||
| 45 | foreach ($data as $fieldName => $fieldValue) { |
||
| 46 | switch ($fieldName) { |
||
| 47 | case 'company': |
||
| 48 | $item->setCompany($fieldValue); |
||
| 49 | break; |
||
| 50 | case 'address1': |
||
| 51 | $item->setAddress1($fieldValue); |
||
| 52 | break; |
||
| 53 | case 'address2': |
||
| 54 | $item->setAddress2($fieldValue); |
||
| 55 | break; |
||
| 56 | case 'city': |
||
| 57 | $item->setCity($fieldValue); |
||
| 58 | break; |
||
| 59 | case 'zip': |
||
| 60 | $item->setZip($fieldValue); |
||
| 61 | break; |
||
| 62 | case 'country': |
||
| 63 | $item->setCountry($fieldValue); |
||
| 64 | break; |
||
| 65 | case 'phone': |
||
| 66 | $item->setPhone($fieldValue); |
||
| 67 | break; |
||
| 68 | case 'state': |
||
| 69 | $item->setState($fieldValue); |
||
| 70 | break; |
||
| 71 | } |
||
| 72 | } |
||
| 73 | } |
||
| 74 | |||
| 75 | return $item; |
||
| 76 | } |
||
| 99 |