Conditions | 10 |
Paths | 4 |
Total Lines | 49 |
Code Lines | 31 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
99 | public function OAuth($request) |
||
100 | { |
||
101 | $denied = $request->getVar('denied'); |
||
102 | $token = $request->getVar('oauth_token'); |
||
103 | $verifier = $request->getVar('oauth_verifier'); |
||
104 | |||
105 | $sessionRequestToken = $this->twitterService->getSessionOAuthToken(); |
||
106 | |||
107 | $this->twitterService->clearSessionOAuthToken(); |
||
108 | |||
109 | $form = $this->getEditForm(); |
||
110 | |||
111 | if ( |
||
112 | $denied || |
||
113 | !$token || |
||
114 | !$verifier || |
||
115 | !$sessionRequestToken || |
||
116 | !array_key_exists('oauth_token', $sessionRequestToken) || |
||
117 | !array_key_exists('oauth_token_secret', $sessionRequestToken) || |
||
118 | $token !== $sessionRequestToken['oauth_token'] |
||
119 | ) { |
||
120 | return $this->handleOAuthError($this->Link(), $form); |
||
121 | } |
||
122 | |||
123 | $accessToken = $this->twitterService->getAccessToken( |
||
124 | $sessionRequestToken['oauth_token'], |
||
125 | $sessionRequestToken['oauth_token_secret'], |
||
126 | $verifier |
||
127 | ); |
||
128 | |||
129 | if (!$accessToken) { |
||
130 | return $this->handleOAuthError($this->Link(), $form); |
||
131 | } |
||
132 | |||
133 | $twitterAccount = TwitterAccount::get() |
||
134 | ->filter(['Title' => $accessToken['screen_name']]) |
||
135 | ->first(); |
||
136 | |||
137 | if (!$twitterAccount) { |
||
138 | return $this->handleOAuthError($this->Link(), $form); |
||
139 | } |
||
140 | |||
141 | $twitterAccount->setAccessToken($accessToken); |
||
142 | $twitterAccount->write(); |
||
143 | |||
144 | $form->sessionMessage(_t('Twitter.MessageOAuthSuccess', 'Successfully authorised your account.'), 'good'); |
||
145 | |||
146 | return Controller::curr()->redirect($this->Link()); |
||
147 | } |
||
148 | } |
||
176 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.