| Conditions | 11 |
| Paths | 28 |
| Total Lines | 66 |
| Code Lines | 43 |
| 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 |
||
| 63 | public function process(Request $request) |
||
| 64 | { |
||
| 65 | $output = ['success' => false, 'already_invited' => false, 'already_a_member' => false, 'hit_limit' => false]; |
||
| 66 | |||
| 67 | $formType = $this->formFactory->create(get_class($this->userInviteType)); |
||
| 68 | $requestHander = $this->requestHandlerManager->getRequestHandler($request); |
||
| 69 | |||
| 70 | if ($request->isMethod('POST')) { |
||
| 71 | $requestHander->handleForm($formType, $request); |
||
| 72 | if ($formType->isSubmitted() && $formType->isValid()) { |
||
| 73 | $email = $formType->getData()['email']; |
||
| 74 | $role = $formType->getData()['role'] ?? $this->defaultRole; |
||
| 75 | $output['processed'] = true; |
||
| 76 | try { |
||
| 77 | $user = $this->security->getUser(); |
||
| 78 | if (!$user instanceof UserInterface) { |
||
| 79 | throw new \InvalidArgumentException('Not a user'); |
||
| 80 | } |
||
| 81 | |||
| 82 | if (!$user instanceof MemberInterface) { |
||
| 83 | $this->getLogger()->critical('A user tried to send a team invite when not a member of a team'); |
||
| 84 | throw new \InvalidArgumentException('Not a member of a team'); |
||
| 85 | } |
||
| 86 | $team = $this->teamRepository->getByMember($user); |
||
| 87 | |||
| 88 | if ($this->inviteCodeRepository->hasInviteForEmailAndTeam($email, $team)) { |
||
| 89 | throw new AlreadyInvitedException(); |
||
| 90 | } |
||
| 91 | |||
| 92 | if (!in_array($role, $this->roles) && $this->defaultRole !== $role) { |
||
| 93 | $this->getLogger()->error('A team invite was not sent due an invalid role being used', ['role' => $role]); |
||
| 94 | throw new GeneralException('Invalid role'); |
||
| 95 | } |
||
| 96 | |||
| 97 | $inviteCode = $this->entityFactory->buildTeamInviteCode($user, $team, $email, $role); |
||
| 98 | if (!$this->authorizationChecker->isGranted(TeamInviteCode::AUTH_CHECKER_ATTRIBUTE, $inviteCode)) { |
||
| 99 | $output['success'] = false; |
||
| 100 | $output['hit_limit'] = true; |
||
| 101 | $this->getLogger()->info('A team invite was not sent due to plan limits'); |
||
| 102 | |||
| 103 | return $requestHander->generateErrorOutput($formType, $output); |
||
| 104 | } |
||
| 105 | |||
| 106 | $this->dispatcher->dispatch(new PreTeamInviteEvent($user, $team, $inviteCode), PreTeamInviteEvent::NAME); |
||
| 107 | $this->inviteCodeRepository->save($inviteCode); |
||
| 108 | $message = $this->messageFactory->getTeamInviteMessage($user, $team, $inviteCode); |
||
| 109 | |||
| 110 | $this->sender->send($message); |
||
| 111 | $this->dispatcher->dispatch(new PostTeamInviteEvent($user, $team, $inviteCode), PostTeamInviteEvent::NAME); |
||
| 112 | $output['success'] = true; |
||
| 113 | $this->requestStack->getSession()->getFlashBag()->add('success', 'parthenon.user.team_invite.success'); |
||
|
|
|||
| 114 | $this->getLogger()->info('A team invite was successfully sent'); |
||
| 115 | } catch (AlreadyInvitedException $e) { |
||
| 116 | $this->getLogger()->info('A team invite failed to be created due to one already existing'); |
||
| 117 | |||
| 118 | $this->requestStack->getSession()->getFlashBag()->add('error', 'parthenon.user.team_invite.already_invited'); |
||
| 119 | $output['already_invited'] = true; |
||
| 120 | |||
| 121 | return $requestHander->generateErrorOutput($formType, $output); |
||
| 122 | } |
||
| 123 | } |
||
| 124 | } |
||
| 125 | |||
| 126 | $output['form'] = $formType->createView(); |
||
| 127 | |||
| 128 | return $requestHander->generateDefaultOutput($formType, $output); |
||
| 129 | } |
||
| 131 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.