Conditions | 8 |
Paths | 47 |
Total Lines | 53 |
Code Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
120 | public function getInstall($key) |
||
121 | { |
||
122 | $pluginData = $this->fetchPluginData(); |
||
123 | |||
124 | try { |
||
125 | if(isset($pluginData[$key])) { |
||
126 | $plugin = $pluginData[$key]; |
||
127 | |||
128 | // Create temp file of zip plugin |
||
129 | $temp = tmpfile(); |
||
130 | fwrite($temp, file_get_contents($plugin['url_download'])); |
||
131 | $filename = stream_get_meta_data($temp)['uri']; |
||
132 | |||
133 | // Extract zip plugin |
||
134 | $zip = new \ZipArchive; |
||
135 | $res = $zip->open($filename); |
||
136 | if ($res === TRUE) { |
||
137 | $zip->extractTo(app_path('CBPlugins')); |
||
138 | $dirName = $zip->getNameIndex(0); |
||
139 | $zip->close(); |
||
140 | fclose($temp); |
||
141 | |||
142 | // Rename |
||
143 | if(file_exists(app_path("CBPlugins/".$key))) rrmdir(app_path("CBPlugins/".$key)); |
||
144 | rename(app_path("CBPlugins/".$dirName), app_path("CBPlugins/".$key)); |
||
145 | |||
146 | // Read Plugin JSON |
||
147 | $pluginJson = json_decode(file_get_contents(app_path("CBPlugins/".$key."/plugin.json")), true); |
||
148 | |||
149 | // Check if has asset |
||
150 | if($pluginJson && $pluginJson['asset']) { |
||
151 | // Check destination folder is ready |
||
152 | if(file_exists(public_path("cb_asset/".$key))) { |
||
153 | rrmdir(public_path("cb_asset/".$key)); |
||
154 | } |
||
155 | |||
156 | // Create directory empty |
||
157 | mkdir(public_path("cb_asset/".$key)); |
||
158 | |||
159 | // Copy asset |
||
160 | $this->recursiveCopy(app_path("CBPlugins/".$key."/".$pluginJson['asset']), public_path("cb_asset/".$key)); |
||
161 | } |
||
162 | |||
163 | return response()->json(['status'=>true,'message'=>'Install / update plugin has been succesfull!']); |
||
164 | |||
165 | } else { |
||
166 | return response()->json(['status'=>false,'message'=>"Failed to install/update, can't open the plugin archive"]); |
||
167 | } |
||
168 | }else{ |
||
169 | return response()->json(['status'=>false,'message'=>'Failed to install/update, plugin key is not found']); |
||
170 | } |
||
171 | } catch (\Exception $e) { |
||
172 | return response()->json(['status'=>false,'message'=>'Something went wrong!']); |
||
173 | } |
||
215 | } |