Conditions | 9 |
Paths | 12 |
Total Lines | 54 |
Code Lines | 35 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
46 | private function updateOauthClient() |
||
47 | { |
||
48 | if (!$this->db->tableExists('{{%oauth_providers}}')) { |
||
49 | return true; |
||
50 | } |
||
51 | |||
52 | // Get OAuth clients for Dailymotion, YouTube and Vimeo, from `oauth_providers` table |
||
53 | $providers = (new Query()) |
||
54 | ->select('*') |
||
55 | ->from(['{{%oauth_providers}}']) |
||
56 | ->where(['class' => ['google', 'vimeo']]) |
||
57 | ->all(); |
||
58 | |||
59 | // Get plugin settings |
||
60 | $result = (new Query()) |
||
61 | ->select('*') |
||
62 | ->from(['{{%plugins}}']) |
||
63 | ->where(['handle' => 'videos']) |
||
64 | ->one(); |
||
65 | |||
66 | if (!$result) { |
||
67 | return true; |
||
68 | } |
||
69 | |||
70 | if (!isset($result['settings'])) { |
||
71 | return true; |
||
72 | } |
||
73 | |||
74 | $settings = Json::decode($result['settings']); |
||
75 | |||
76 | foreach ($providers as $provider) { |
||
77 | switch ($provider['class']) { |
||
78 | case 'dailymotion': |
||
79 | $providerHandle = 'dailymotion'; |
||
80 | break; |
||
81 | case 'vimeo': |
||
82 | $providerHandle = 'vimeo'; |
||
83 | break; |
||
84 | case 'google': |
||
85 | $providerHandle = 'youtube'; |
||
86 | break; |
||
87 | default: |
||
88 | $providerHandle = null; |
||
89 | } |
||
90 | |||
91 | if (!$providerHandle) { |
||
92 | continue; |
||
93 | } |
||
94 | |||
95 | $settings['oauthProviderOptions'][$providerHandle]['clientId'] = $provider['clientId']; |
||
96 | $settings['oauthProviderOptions'][$providerHandle]['clientSecret'] = $provider['clientSecret']; |
||
97 | } |
||
98 | |||
99 | $this->update('{{%plugins}}', ['settings' => Json::encode($settings)], ['handle' => 'videos']); |
||
100 | } |
||
111 |