| Conditions | 11 |
| Paths | 30 |
| Total Lines | 61 |
| Code Lines | 32 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 117 | public function finalStep(array &$state, Request $request): void |
||
| 118 | { |
||
| 119 | $requestToken = unserialize($state['authtwitter:authdata:requestToken']); |
||
| 120 | |||
| 121 | $oauth_token = $request->get('oauth_token'); |
||
| 122 | if ($oauth_token === null) { |
||
| 123 | throw new Error\BadRequest("Missing oauth_token parameter."); |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($requestToken->getIdentifier() !== $oauth_token) { |
||
| 127 | throw new Error\BadRequest("Invalid oauth_token parameter."); |
||
| 128 | } |
||
| 129 | |||
| 130 | $oauth_verifier = $request->get('oauth_verifier'); |
||
| 131 | if ($oauth_verifier === null) { |
||
| 132 | throw new Error\BadRequest("Missing oauth_verifier parameter."); |
||
| 133 | } |
||
| 134 | |||
| 135 | $server = new TwitterServer( |
||
| 136 | [ |
||
| 137 | 'identifier' => $this->key, |
||
| 138 | 'secret' => $this->secret, |
||
| 139 | ] |
||
| 140 | ); |
||
| 141 | |||
| 142 | $tokenCredentials = $server->getTokenCredentials( |
||
| 143 | $requestToken, |
||
| 144 | $request->get('oauth_token'), |
||
| 145 | $request->get('oauth_verifier') |
||
| 146 | ); |
||
| 147 | |||
| 148 | $state['token_credentials'] = serialize($tokenCredentials); |
||
| 149 | $userdata = $server->getUserDetails($tokenCredentials); |
||
| 150 | |||
| 151 | $attributes = []; |
||
| 152 | |||
| 153 | foreach ($userdata->getIterator() as $key => $value) { |
||
| 154 | if (is_string($value)) { |
||
| 155 | $attributes['twitter.' . $key] = [$value]; |
||
| 156 | } else { |
||
| 157 | // Either the urls or the extra array |
||
| 158 | } |
||
| 159 | } |
||
| 160 | |||
| 161 | foreach ($userdata->urls as $key => $value) { |
||
| 162 | if (is_string($value)) { |
||
| 163 | $attributes['twitter.' . $key] = [$value]; |
||
| 164 | } else { |
||
| 165 | // Something funky.. Maybe the API has changed? |
||
| 166 | } |
||
| 167 | } |
||
| 168 | |||
| 169 | foreach ($userdata->extra as $key => $value) { |
||
| 170 | if (is_string($value) || is_int($value)) { |
||
| 171 | $attributes['twitter.' . $key] = [strval($value)]; |
||
| 172 | } else { |
||
| 173 | // Something funky.. Maybe the API has changed? |
||
| 174 | } |
||
| 175 | } |
||
| 176 | |||
| 177 | $state['Attributes'] = $attributes; |
||
| 178 | } |
||
| 180 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.