| Conditions | 11 |
| Paths | 640 |
| Total Lines | 47 |
| Code Lines | 23 |
| 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 |
||
| 21 | public function denormalize(mixed $data, string $type, ?string $format = null, array $context = []) |
||
| 22 | { |
||
| 23 | $context[self::ALREADY_CALLED] = true; |
||
| 24 | |||
| 25 | $user = $context['object_to_populate'] ?? new User(); |
||
| 26 | |||
| 27 | if (isset($data['userName'])) { |
||
| 28 | $user->setUsername($data['userName']); |
||
| 29 | } |
||
| 30 | |||
| 31 | if (isset($data['active'])) { |
||
| 32 | $user->setActive((int) $data['active']); |
||
| 33 | } |
||
| 34 | |||
| 35 | if (isset($data['name'])) { |
||
| 36 | $name = $data['name']; |
||
| 37 | |||
| 38 | if (isset($name['givenName'])) { |
||
| 39 | $user->setFirstName($name['givenName']); |
||
| 40 | } |
||
| 41 | |||
| 42 | if (isset($name['familyName'])) { |
||
| 43 | $user->setLastName($name['familyName']); |
||
| 44 | } |
||
| 45 | } |
||
| 46 | |||
| 47 | if ($email = self::getPrimaryValue($data, 'emails')) { |
||
| 48 | $user->setEmail($email); |
||
| 49 | } |
||
| 50 | |||
| 51 | if ($phone = self::getPrimaryValue($data, 'phoneNumbers')) { |
||
| 52 | $user->setPhone($phone); |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($address = self::getPrimaryValue($data, 'addresses', 'formatted')) { |
||
| 56 | $user->setAddress($address); |
||
| 57 | } |
||
| 58 | |||
| 59 | if (isset($data['locale'])) { |
||
| 60 | $user->setLocale(substr($data['locale'], 0, 10)); |
||
| 61 | } |
||
| 62 | |||
| 63 | if (isset($data['timezone'])) { |
||
| 64 | $user->setTimezone($data['timezone']); |
||
| 65 | } |
||
| 66 | |||
| 67 | return $user; |
||
| 68 | } |
||
| 107 |