Conditions | 4 |
Paths | 6 |
Total Lines | 52 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
19 | public function actionConnect() |
||
20 | { |
||
21 | // Get referer |
||
22 | $referer = craft()->httpSession->get('youtube.referer'); |
||
23 | |||
24 | // If not set, set it |
||
25 | if (!$referer) { |
||
26 | $referer = craft()->request->getUrlReferrer(); |
||
27 | craft()->httpSession->add('youtube.referer', $referer); |
||
28 | } |
||
29 | |||
30 | // Set YouTube OAuth options |
||
31 | $options = array( |
||
32 | 'plugin' => 'youtube', |
||
33 | 'provider' => 'google', |
||
34 | 'scope' => array( |
||
35 | 'https://www.googleapis.com/auth/userinfo.profile', |
||
36 | 'https://www.googleapis.com/auth/userinfo.email', |
||
37 | 'https://www.googleapis.com/auth/youtube', |
||
38 | 'https://www.googleapis.com/auth/youtube.upload', |
||
39 | ), |
||
40 | 'authorizationOptions' => array( |
||
41 | 'access_type' => 'offline', |
||
42 | 'approval_prompt' => 'force', |
||
43 | ), |
||
44 | ); |
||
45 | |||
46 | // Connect |
||
47 | if ($response = craft()->oauth->connect($options)) { |
||
48 | if ($response['success']) { |
||
49 | |||
50 | // Get token |
||
51 | $token = $response['token']; |
||
52 | |||
53 | // Save token |
||
54 | craft()->youTube_oauth->saveToken($token); |
||
55 | |||
56 | // Session notice |
||
57 | craft()->userSession->setNotice(Craft::t('Connected.')); |
||
58 | } else { |
||
59 | // Session notice |
||
60 | craft()->userSession->setError(Craft::t($response['errorMsg'])); |
||
61 | } |
||
62 | } else { |
||
63 | // session error |
||
64 | craft()->userSession->setError(Craft::t('Couldn’t connect')); |
||
65 | } |
||
66 | |||
67 | // Redirect |
||
68 | craft()->httpSession->remove('youtube.referer'); |
||
69 | $this->redirect($referer); |
||
70 | } |
||
71 | |||
88 |