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 |
||
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 | } else { |
||
156 | // Either the urls or the extra array |
||
157 | } |
||
158 | } |
||
159 | |||
160 | foreach ($userdata->urls as $key => $value) { |
||
161 | if (is_string($value)) { |
||
162 | $attributes['twitter.' . $key] = [$value]; |
||
163 | } else { |
||
164 | // Something funky.. Maybe the API has changed? |
||
165 | } |
||
166 | } |
||
167 | |||
168 | foreach ($userdata->extra as $key => $value) { |
||
169 | if (is_string($value) || is_int($value)) { |
||
170 | $attributes['twitter.' . $key] = [strval($value)]; |
||
171 | } else { |
||
172 | // Something funky.. Maybe the API has changed? |
||
173 | } |
||
174 | } |
||
175 | |||
176 | $state['Attributes'] = $attributes; |
||
177 | } |
||
179 |
In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.