| Conditions | 4 |
| Paths | 8 |
| Total Lines | 60 |
| Code Lines | 35 |
| 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 |
||
| 30 | public function normalize(mixed $object, ?string $format = null, array $context = []): array |
||
| 31 | { |
||
| 32 | /** @var User $user */ |
||
| 33 | $user = $object; |
||
| 34 | |||
| 35 | $uuid = $user->getUuid(); |
||
| 36 | |||
| 37 | $userInfo = [ |
||
| 38 | 'schemas' => ['urn:ietf:params:scim:schemas:core:2.0:User'], |
||
| 39 | 'id' => $uuid, |
||
| 40 | 'userName' => $user->getUsername(), |
||
| 41 | 'name' => [ |
||
| 42 | 'formatted' => $this->nameConventionHelper->getPersonName($user), |
||
| 43 | 'givenName' => $user->getFirstname(), |
||
| 44 | 'familyName' => $user->getLastName(), |
||
| 45 | ], |
||
| 46 | 'emails' => [ |
||
| 47 | [ |
||
| 48 | 'value' => $user->getEmail(), |
||
| 49 | 'type' => 'work', |
||
| 50 | 'primary' => true, |
||
| 51 | ], |
||
| 52 | ], |
||
| 53 | 'active' => $user->isActive(), |
||
| 54 | 'timezone' => $user->getTimezone(), |
||
| 55 | 'meta' => [ |
||
| 56 | 'resourceType' => 'User', |
||
| 57 | 'created' => $user->getCreatedAt()?->format('c'), |
||
| 58 | 'lastModified' => $user->getUpdatedAt()?->format('c'), |
||
| 59 | 'location' => $this->router->generate( |
||
| 60 | 'scim_user', |
||
| 61 | ['uuid' => $uuid], |
||
| 62 | UrlGeneratorInterface::ABSOLUTE_URL |
||
| 63 | ), |
||
| 64 | ], |
||
| 65 | ]; |
||
| 66 | |||
| 67 | if ($externalId = $this->scimHelper->getExternalId($user)) { |
||
| 68 | $userInfo['externalId'] = $externalId; |
||
| 69 | } |
||
| 70 | |||
| 71 | if ($phone = $user->getPhone()) { |
||
| 72 | $userInfo['phoneNumbers'] = [ |
||
| 73 | [ |
||
| 74 | 'type' => 'work', |
||
| 75 | 'value' => $phone, |
||
| 76 | ], |
||
| 77 | ]; |
||
| 78 | } |
||
| 79 | |||
| 80 | if ($address = $user->getAddress()) { |
||
| 81 | $userInfo['addresses'] = [ |
||
| 82 | [ |
||
| 83 | 'type' => 'work', |
||
| 84 | 'formatted' => $address, |
||
| 85 | ] |
||
| 86 | ]; |
||
| 87 | } |
||
| 88 | |||
| 89 | return $userInfo; |
||
| 90 | } |
||
| 108 |