| Conditions | 8 |
| Paths | 12 |
| Total Lines | 53 |
| Code Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 116 | public function finalStep(array &$state, Request $request): void |
||
| 117 | { |
||
| 118 | $requestToken = unserialize($state['authtwitter:authdata:requestToken']); |
||
| 119 | |||
| 120 | $oauth_token = $request->get('oauth_token'); |
||
| 121 | if ($oauth_token === null) { |
||
| 122 | throw new Error\BadRequest("Missing oauth_token parameter."); |
||
| 123 | } |
||
| 124 | |||
| 125 | if ($requestToken->getIdentifier() !== $oauth_token) { |
||
| 126 | throw new Error\BadRequest("Invalid oauth_token parameter."); |
||
| 127 | } |
||
| 128 | |||
| 129 | $oauth_verifier = $request->get('oauth_verifier'); |
||
| 130 | if ($oauth_verifier === null) { |
||
| 131 | throw new Error\BadRequest("Missing oauth_verifier parameter."); |
||
| 132 | } |
||
| 133 | |||
| 134 | $server = new TwitterServer( |
||
| 135 | [ |
||
| 136 | 'identifier' => $this->key, |
||
| 137 | 'secret' => $this->secret, |
||
| 138 | ] |
||
| 139 | ); |
||
| 140 | |||
| 141 | $tokenCredentials = $server->getTokenCredentials( |
||
| 142 | $requestToken, |
||
| 143 | $request->get('oauth_token'), |
||
| 144 | $request->get('oauth_verifier') |
||
| 145 | ); |
||
| 146 | |||
| 147 | $state['token_credentials'] = serialize($tokenCredentials); |
||
| 148 | $userdata = $server->getUserDetails($tokenCredentials); |
||
| 149 | |||
| 150 | $attributes = []; |
||
| 151 | |||
| 152 | foreach ($userdata->getIterator() as $key => $value) { |
||
| 153 | if (is_string($value)) { |
||
| 154 | $attributes['twitter.' . $key] = [$value]; |
||
| 155 | } |
||
| 156 | } |
||
| 157 | |||
| 158 | foreach ($userdata->extra as $key => $value) { |
||
| 159 | if (is_string($value)) { |
||
| 160 | $attributes['twitter.' . $key] = [$value]; |
||
| 161 | } |
||
| 162 | } |
||
| 163 | |||
| 164 | $attributes['twitter_at_screen_name'] = ['@' . $userdata->nickname]; |
||
| 165 | $attributes['twitter_screen_n_realm'] = [$userdata->nickname . '@twitter.com']; |
||
| 166 | $attributes['twitter_targetedID'] = ['http://twitter.com!' . $userdata->uid]; |
||
| 167 | |||
| 168 | $state['Attributes'] = $attributes; |
||
| 169 | } |
||
| 171 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.