Conditions | 6 |
Paths | 4 |
Total Lines | 57 |
Code Lines | 26 |
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 |
||
66 | public function grantNewAccessToken() |
||
67 | { |
||
68 | if (empty($_GET['code']) |
||
69 | || empty($_GET['state']) |
||
70 | || $_GET['state'] !== $this->apiConfiguration->ourSecretState() |
||
71 | ) { |
||
72 | throw new ThirdPartyConnectionFailedException('Invalid request!'); |
||
73 | } |
||
74 | |||
75 | $headers = array( |
||
76 | 'Authorization' => sprintf( |
||
77 | 'Basic %s', |
||
78 | base64_encode( |
||
79 | sprintf('%s:%s', $this->apiConfiguration->clientId(), $this->apiConfiguration->clientSecret()) |
||
80 | ) |
||
81 | ), |
||
82 | ); |
||
83 | |||
84 | $accessTokenJsonInfo = $this->curlClient->postUrlEncoded( |
||
85 | sprintf("%s/oauth/token", self::API_BASE), |
||
86 | sprintf( |
||
87 | 'client_id=%s&client_secret=%s&grant_type=authorization_code&redirect_uri=%s&code=%s', |
||
88 | $this->apiConfiguration->clientId(), |
||
89 | $this->apiConfiguration->clientSecret(), |
||
90 | urlencode($this->apiConfiguration->redirectUrl()), |
||
91 | $_GET['code'] |
||
92 | ), |
||
93 | $headers |
||
94 | ); |
||
95 | |||
96 | $accessTokenInfo = json_decode($accessTokenJsonInfo, true); |
||
97 | if (empty($accessTokenInfo['access_token'])) { |
||
98 | throw new ThirdPartyConnectionFailedException( |
||
99 | 'An error occurred while getting the access.' |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | $accessToken = new CommonAccessToken($accessTokenInfo['access_token'], ThirdParty::ZOOM); |
||
104 | if (!empty($accessTokenInfo['refresh_token'])) { |
||
105 | $accessToken->setRefreshToken($accessTokenInfo['refresh_token']); |
||
106 | } |
||
107 | |||
108 | /* |
||
109 | $refreshTokenJsonInfo = $this->curlClient->post( |
||
110 | sprintf("%s/oauth/token?grant_type=refresh_token&refresh_token=%s", self::API_BASE, $accessTokenInfo['refresh_token']), |
||
111 | array(), |
||
112 | $headers |
||
113 | ); |
||
114 | |||
115 | // if refresh token found, return that or return the access token |
||
116 | $refreshTokenInfo = json_decode($refreshTokenJsonInfo, true); |
||
117 | if (!empty($refreshTokenInfo['access_token']) && !empty($refreshTokenInfo['refresh_token'])) { |
||
118 | $accessToken = new CommonAccessToken($refreshTokenInfo['access_token'], ThirdParty::ZOOM); |
||
119 | $accessToken->setRefreshToken($refreshTokenInfo['refresh_token']); |
||
120 | }//*/ |
||
121 | |||
122 | return $accessToken; |
||
123 | } |
||
187 |