Conditions | 7 |
Paths | 11 |
Total Lines | 52 |
Code Lines | 32 |
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 |
||
47 | public function insertDefaultData() |
||
48 | { |
||
49 | $row = (new Query()) |
||
50 | ->select('*') |
||
51 | ->from(['{{%plugins}}']) |
||
52 | ->where(['handle' => 'analytics']) |
||
53 | ->one(); |
||
54 | |||
55 | if (!$row) { |
||
56 | echo " done\n"; |
||
57 | return null; |
||
58 | } |
||
59 | |||
60 | if (!isset($row['settings'])) { |
||
61 | echo " done\n"; |
||
62 | return null; |
||
63 | } |
||
64 | |||
65 | $forceConnect = false; |
||
66 | $token = null; |
||
67 | $settingsJson = $row['settings']; |
||
68 | $settings = Json::decode($settingsJson); |
||
69 | |||
70 | if($settings) { |
||
71 | $forceConnect = $settings['forceConnect']; |
||
72 | |||
73 | if(isset($settings['token'])) { |
||
74 | $token = $settings['token']; |
||
75 | } |
||
76 | } |
||
77 | |||
78 | // Populate the analytics_info table |
||
79 | echo ' > populate the analytics_info table ...'; |
||
80 | Plugin::getInstance()->saveInfo(new Info([ |
||
81 | 'forceConnect' => $forceConnect, |
||
82 | 'token' => $token, |
||
83 | ])); |
||
84 | echo " done\n"; |
||
85 | |||
86 | // Get rid of the old plugin settings |
||
87 | echo ' > remove old plugin settings ...'; |
||
88 | if($settings) { |
||
89 | unset($settings['forceConnect']); |
||
90 | |||
91 | if(isset($settings['token'])) { |
||
92 | unset($settings['token']); |
||
93 | } |
||
94 | |||
95 | $settingsJson = Json::encode($settings); |
||
96 | $this->update('{{%plugins}}', ['settings' => $settingsJson], ['id' => $row['id']]); |
||
97 | } |
||
98 | echo " done\n"; |
||
99 | } |
||
110 |