Conditions | 12 |
Paths | 54 |
Total Lines | 70 |
Code Lines | 38 |
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 |
||
130 | public function getInstall($key) |
||
131 | { |
||
132 | ini_set("memory_limit","192M"); |
||
133 | set_time_limit(500); |
||
134 | |||
135 | $pluginData = $this->fetchPluginData(); |
||
136 | |||
137 | try { |
||
138 | if(isset($pluginData[$key])) { |
||
139 | $plugin = $pluginData[$key]; |
||
140 | |||
141 | if(isset($plugin['source']) && $plugin['source'] == "composer") { |
||
142 | |||
143 | if(isset($plugin['package']) && isset($plugin['service_provider'])) { |
||
144 | // Make a composer |
||
145 | $output = ComposerHelper::composerRequire($plugin['package'], $plugin['service_provider']); |
||
146 | |||
147 | return response()->json(['status'=>true,'message'=>$output]); |
||
148 | } else { |
||
149 | return response()->json(['status'=>true,'message'=>'Installation is failed, there is no package and or service provider']); |
||
150 | } |
||
151 | |||
152 | } else { |
||
153 | // Create temp file of zip plugin |
||
154 | $temp = tmpfile(); |
||
155 | fwrite($temp, file_get_contents($plugin['url_download'])); |
||
156 | $filename = stream_get_meta_data($temp)['uri']; |
||
157 | |||
158 | // Extract zip plugin |
||
159 | $zip = new \ZipArchive; |
||
160 | $res = $zip->open($filename); |
||
161 | if ($res === TRUE) { |
||
162 | $zip->extractTo(app_path('CBPlugins')); |
||
163 | $dirName = $zip->getNameIndex(0); |
||
164 | $zip->close(); |
||
165 | fclose($temp); |
||
166 | |||
167 | // Rename |
||
168 | if(file_exists(app_path("CBPlugins/".$key))) rrmdir(app_path("CBPlugins/".$key)); |
||
169 | rename(app_path("CBPlugins/".$dirName), app_path("CBPlugins/".$key)); |
||
170 | |||
171 | // Read Plugin JSON |
||
172 | $pluginJson = json_decode(file_get_contents(app_path("CBPlugins/".$key."/plugin.json")), true); |
||
173 | |||
174 | // Check if has asset |
||
175 | if($pluginJson && $pluginJson['asset']) { |
||
176 | // Check destination folder is ready |
||
177 | if(file_exists(public_path("cb_asset/".$key))) { |
||
178 | rrmdir(public_path("cb_asset/".$key)); |
||
179 | } |
||
180 | |||
181 | // Create directory empty |
||
182 | mkdir(public_path("cb_asset/".$key)); |
||
183 | |||
184 | // Copy asset |
||
185 | $this->recursiveCopy(app_path("CBPlugins/".$key."/".$pluginJson['asset']), public_path("cb_asset/".$key)); |
||
186 | } |
||
187 | |||
188 | return response()->json(['status'=>true,'message'=>'Install / update plugin has been succesfull!']); |
||
189 | |||
190 | } else { |
||
191 | return response()->json(['status'=>false,'message'=>"Failed to install/update, can't open the plugin archive"]); |
||
192 | } |
||
193 | } |
||
194 | |||
195 | }else{ |
||
196 | return response()->json(['status'=>false,'message'=>'Failed to install/update, plugin key is not found']); |
||
197 | } |
||
198 | } catch (\Exception $e) { |
||
199 | return response()->json(['status'=>false,'message'=>'Something went wrong!']); |
||
200 | } |
||
245 | } |