| Conditions | 3 |
| Paths | 3 |
| Total Lines | 66 |
| Code Lines | 45 |
| 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 |
||
| 36 | public function registerUser(array $azureUserInfo, string $azureUidKey = 'objectId'): User |
||
| 37 | { |
||
| 38 | if (empty($azureUserInfo)) { |
||
| 39 | throw new UnauthorizedHttpException('User info not found.'); |
||
| 40 | } |
||
| 41 | |||
| 42 | [ |
||
| 43 | $firstNme, |
||
| 44 | $lastName, |
||
| 45 | $username, |
||
| 46 | $email, |
||
| 47 | $phone, |
||
| 48 | $authSource, |
||
| 49 | $active, |
||
| 50 | $extra, |
||
| 51 | ] = $this->formatUserData($azureUserInfo, $azureUidKey); |
||
| 52 | |||
| 53 | $userId = $this->getUserIdByVerificationOrder($azureUserInfo, $azureUidKey); |
||
| 54 | |||
| 55 | if (empty($userId)) { |
||
| 56 | $user = (new User()) |
||
| 57 | ->setCreatorId($this->userRepository->getRootUser()->getId()) |
||
| 58 | ; |
||
| 59 | } else { |
||
| 60 | $user = $this->userRepository->find($userId); |
||
| 61 | } |
||
| 62 | |||
| 63 | $user |
||
| 64 | ->setFirstname($firstNme) |
||
| 65 | ->setLastname($lastName) |
||
| 66 | ->setEmail($email) |
||
| 67 | ->setUsername($username) |
||
| 68 | ->setPlainPassword('azure') |
||
| 69 | ->setStatus(STUDENT) |
||
| 70 | ->setAuthSource($authSource) |
||
| 71 | ->setPhone($phone) |
||
| 72 | ->setActive($active) |
||
| 73 | ->setRoleFromStatus(STUDENT) |
||
| 74 | ; |
||
| 75 | |||
| 76 | $this->userRepository->updateUser($user); |
||
| 77 | |||
| 78 | $url = $this->urlHelper->getCurrent(); |
||
| 79 | $url->addUser($user); |
||
| 80 | |||
| 81 | $this->entityManager->flush(); |
||
| 82 | |||
| 83 | $this->extraFieldValuesRepo->updateItemData( |
||
| 84 | $this->getOrganizationEmailField(), |
||
| 85 | $user, |
||
| 86 | $extra['extra_'.self::EXTRA_FIELD_ORGANISATION_EMAIL] |
||
| 87 | ); |
||
| 88 | |||
| 89 | $this->extraFieldValuesRepo->updateItemData( |
||
| 90 | $this->getAzureIdField(), |
||
| 91 | $user, |
||
| 92 | $extra['extra_'.self::EXTRA_FIELD_AZURE_ID] |
||
| 93 | ); |
||
| 94 | |||
| 95 | $this->extraFieldValuesRepo->updateItemData( |
||
| 96 | $this->getAzureUidField(), |
||
| 97 | $user, |
||
| 98 | $extra['extra_'.self::EXTRA_FIELD_AZURE_UID] |
||
| 99 | ); |
||
| 100 | |||
| 101 | return $user; |
||
| 102 | } |
||
| 199 |