| Conditions | 5 |
| Paths | 4 |
| Total Lines | 59 |
| Code Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 83 | public function validateAuthorizeAction() |
||
| 84 | { |
||
| 85 | $request = $this->getRequest(); |
||
| 86 | $client = $this->getClient($request); |
||
| 87 | |||
| 88 | if (!$client instanceof \FOS\OAuthServerBundle\Model\ClientInterface) { |
||
| 89 | return parent::validateAuthorizeAction(); |
||
| 90 | } |
||
| 91 | |||
| 92 | /** @var PersonInterface $person */ |
||
| 93 | $person = $this->getUser(); |
||
| 94 | |||
| 95 | /** @var EventDispatcher $dispatcher */ |
||
| 96 | $dispatcher = $this->get('event_dispatcher'); |
||
| 97 | |||
| 98 | $event = new OAuthEvent($person, $client); |
||
| 99 | $dispatcher->dispatch(OAuthEvent::PRE_AUTHORIZATION_PROCESS, $event); |
||
| 100 | |||
| 101 | $isAuthorized = $event->isAuthorizedClient(); |
||
| 102 | $askConsent = $request->get('prompt', null) == 'consent'; |
||
| 103 | |||
| 104 | if ($isAuthorized && !$askConsent) { |
||
| 105 | return $this->handleAuthorize($this->getOAuth2Server(), $isAuthorized); |
||
| 106 | } |
||
| 107 | |||
| 108 | $authEvent = new AuthorizationEvent($person, $client, $request->get('scope')); |
||
| 109 | $dispatcher->dispatch(LoginCidadaoOpenIDEvents::NEW_AUTHORIZATION_REQUEST, $authEvent); |
||
| 110 | $remoteClaims = $authEvent->getRemoteClaims(); |
||
| 111 | |||
| 112 | /** @var OrganizationService $organizationService */ |
||
| 113 | $organizationService = $this->get('organization'); |
||
| 114 | $warnUntrusted = $this->shouldWarnUntrusted($client); |
||
| 115 | $metadata = $this->getMetadata($client); |
||
| 116 | $organization = $organizationService->getOrganization($metadata); |
||
| 117 | |||
| 118 | // Call the lib's original Controller |
||
| 119 | $parentResponse = parent::validateAuthorizeAction(); |
||
| 120 | if (!is_array($parentResponse)) { |
||
| 121 | return $parentResponse; |
||
| 122 | } |
||
| 123 | $parentResponse['scopes'] = $this->removeRemoteScope($parentResponse['scopes']); |
||
| 124 | |||
| 125 | $response = array_merge([ |
||
| 126 | 'qs' => [ |
||
| 127 | 'client_id' => $client->getPublicId(), |
||
| 128 | 'scope' => $parentResponse['scopes'], |
||
| 129 | 'response_type' => $request->get('response_type'), |
||
| 130 | 'redirect_uri' => $request->get('redirect_uri'), |
||
| 131 | 'state' => $request->get('state'), |
||
| 132 | 'nonce' => $request->get('nonce'), |
||
| 133 | ], |
||
| 134 | 'remoteClaims' => $remoteClaims, |
||
| 135 | 'client' => $client, |
||
| 136 | 'metadata' => $metadata, |
||
| 137 | 'organization' => $organization, |
||
| 138 | 'warnUntrusted' => $warnUntrusted, |
||
| 139 | ], $parentResponse); |
||
| 140 | |||
| 141 | return $response; |
||
| 142 | } |
||
| 237 |