Conditions | 10 |
Paths | 9 |
Total Lines | 53 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
57 | public function linkback(Request $request) |
||
58 | { |
||
59 | $authState = $request->get('AuthState'); |
||
60 | if ($authState === null) { |
||
61 | throw new Error\BadRequest('Missing state parameter on twitter linkback endpoint.'); |
||
62 | } |
||
63 | |||
64 | $state = Auth\State::loadState(base64_decode($authState), TwitterSource::STAGE_TEMP); |
||
65 | |||
66 | // Find authentication source |
||
67 | if (is_null($state) || !array_key_exists(TwitterSource::AUTHID, $state)) { |
||
68 | throw new Error\BadRequest('No data in state for ' . TwitterSource::AUTHID); |
||
69 | } |
||
70 | |||
71 | $sourceId = $state[TwitterSource::AUTHID]; |
||
72 | |||
73 | /** @var \SimpleSAML\Module\authtwitter\Auth\Source\Twitter|null $source */ |
||
74 | $source = Auth\Source::getById($sourceId); |
||
75 | |||
76 | if ($source === null) { |
||
77 | throw new Error\BadRequest( |
||
78 | 'Could not find authentication source with id ' . var_export($sourceId, true) |
||
79 | ); |
||
80 | } |
||
81 | |||
82 | $requestToken = unserialize($state['authtwitter:authdata:requestToken']); |
||
83 | |||
84 | $oauth_token = $request->get('oauth_token'); |
||
85 | if ($oauth_token === null) { |
||
86 | throw new Error\BadRequest("Missing oauth_token parameter."); |
||
87 | } |
||
88 | |||
89 | if ($requestToken->getIdentifier() !== $oauth_token) { |
||
90 | throw new Error\BadRequest("Invalid oauth_token parameter."); |
||
91 | } |
||
92 | |||
93 | $oauth_verifier = $request->get('oauth_verifier'); |
||
94 | if ($oauth_verifier === null) { |
||
95 | throw new Error\BadRequest("Missing oauth_verifier parameter."); |
||
96 | } |
||
97 | |||
98 | try { |
||
99 | $source->finalStep($requestToken, $oauth_token, $oauth_verifier); |
||
|
|||
100 | } catch (Error\Exception $e) { |
||
101 | Auth\State::throwException($state, $e); |
||
102 | } catch (Exception $e) { |
||
103 | Auth\State::throwException( |
||
104 | $state, |
||
105 | new Error\AuthSource($sourceId, 'Error on authtwitter linkback endpoint.', $e) |
||
106 | ); |
||
107 | } |
||
108 | |||
109 | return new RunnableResponse([Auth\Source::class, 'completeAuth'], [&$state]); |
||
110 | } |
||
112 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.