Conditions | 10 |
Paths | 4 |
Total Lines | 35 |
Code Lines | 25 |
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 |
||
38 | public function denormalize($data, $class, $format = null, array $context = []) |
||
39 | { |
||
40 | if (is_string($data)) { |
||
41 | $data = json_decode($data, true); |
||
42 | } |
||
43 | |||
44 | /** @var ListItem $item */ |
||
45 | $item = new $class(); |
||
46 | |||
47 | if ($data) { |
||
48 | foreach ($data as $fieldName => $fieldValue) { |
||
49 | switch ($fieldName) { |
||
50 | case 'id': |
||
51 | $item->setId($fieldValue); |
||
52 | break; |
||
53 | case 'name': |
||
54 | $item->setName($fieldValue); |
||
55 | break; |
||
56 | case 'permission_reminder': |
||
57 | $item->setPermissionReminder($fieldValue); |
||
58 | break; |
||
59 | case 'email_type_option': |
||
60 | $item->setEmailTypeOption($fieldValue); |
||
61 | break; |
||
62 | case 'contact': |
||
63 | $item->setContact($this->serializer->denormalize($fieldValue, ListItemContact::class, 'json', [])); |
||
64 | break; |
||
65 | case 'campaign_defaults': |
||
66 | $item->setCampaignDefaults($this->serializer->denormalize($fieldValue, ListItemCampaignDefaults::class, 'json', [])); |
||
67 | break; |
||
68 | } |
||
69 | } |
||
70 | } |
||
71 | |||
72 | return $item; |
||
73 | } |
||
96 |