Conditions | 4 |
Paths | 5 |
Total Lines | 53 |
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 |
||
40 | public function handle() |
||
41 | { |
||
42 | if (! $config = $this->config()) { |
||
43 | $this->error('Please provide a valid configuration.'); |
||
44 | |||
45 | return false; |
||
46 | } |
||
47 | |||
48 | $clientId = $config['client_id']; |
||
49 | $clientSecret = $config['client_secret']; |
||
50 | $scopes = self::ADWORDS_API_SCOPE; |
||
51 | |||
52 | $oauth2 = new OAuth2([ |
||
53 | 'authorizationUri' => self::AUTHORIZATION_URI, |
||
54 | 'redirectUri' => self::REDIRECT_URI, |
||
55 | 'tokenCredentialUri' => CredentialsLoader::TOKEN_CREDENTIAL_URI, |
||
56 | 'clientId' => $clientId, |
||
57 | 'clientSecret' => $clientSecret, |
||
58 | 'scope' => $scopes, |
||
59 | ]); |
||
60 | |||
61 | $this->info("Please sign in to your AdWords account, and open following url:\n"); |
||
62 | $this->line(sprintf( |
||
63 | '%s', |
||
64 | $oauth2->buildFullAuthorizationUri([ |
||
65 | 'access_type' => 'offline', |
||
66 | ]) |
||
67 | )); |
||
68 | |||
69 | $accessToken = $this->ask('Insert your access token'); |
||
70 | |||
71 | try { |
||
72 | $oauth2->setCode($accessToken); |
||
73 | $authToken = $oauth2->fetchAuthToken(); |
||
74 | } catch (Exception $exception) { |
||
75 | $this->error($exception->getMessage()); |
||
76 | |||
77 | return false; |
||
78 | } |
||
79 | |||
80 | if (! isset($authToken)) { |
||
81 | $this->error('Error fetching the refresh token'); |
||
82 | |||
83 | return false; |
||
84 | } |
||
85 | |||
86 | $this->comment('Insert the refresh token in your adwords configuration file (config/adwords-targeting-idea-service.php)'); |
||
87 | |||
88 | $this->info(sprintf( |
||
89 | 'Refresh token: "%s"', |
||
90 | $authToken['refresh_token'] |
||
91 | )); |
||
92 | } |
||
93 | |||
110 |