| Conditions | 12 |
| Paths | 61 |
| Total Lines | 75 |
| Code Lines | 40 |
| 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 |
||
| 84 | public function getInstall($key) |
||
| 85 | { |
||
| 86 | ini_set("memory_limit","192M"); |
||
| 87 | set_time_limit(500); |
||
| 88 | |||
| 89 | $pluginData = $this->fetchPluginData(); |
||
| 90 | |||
| 91 | try { |
||
| 92 | if(isset($pluginData[$key])) { |
||
| 93 | $plugin = $pluginData[$key]; |
||
| 94 | |||
| 95 | if(isset($plugin['source']) && $plugin['source'] == "composer") { |
||
| 96 | |||
| 97 | if(isset($plugin['package']) && isset($plugin['service_provider'])) { |
||
| 98 | // Make a composer |
||
| 99 | $output = ComposerHelper::composerRequire($plugin['package'], $plugin['service_provider']); |
||
| 100 | |||
| 101 | Artisan::call("migrate"); |
||
| 102 | |||
| 103 | return response()->json(['status'=>true,'message'=>$output]); |
||
| 104 | } else { |
||
| 105 | return response()->json(['status'=>true,'message'=>'Installation is failed, there is no package and or service provider']); |
||
| 106 | } |
||
| 107 | |||
| 108 | } else { |
||
| 109 | // Create temp file of zip plugin |
||
| 110 | $temp = tmpfile(); |
||
| 111 | fwrite($temp, file_get_contents($plugin['url_download'])); |
||
| 112 | $filename = stream_get_meta_data($temp)['uri']; |
||
| 113 | |||
| 114 | // Extract zip plugin |
||
| 115 | $zip = new \ZipArchive; |
||
| 116 | $res = $zip->open($filename); |
||
| 117 | if ($res === TRUE) { |
||
| 118 | $zip->extractTo(app_path('CBPlugins')); |
||
| 119 | $dirName = $zip->getNameIndex(0); |
||
| 120 | $zip->close(); |
||
| 121 | fclose($temp); |
||
| 122 | |||
| 123 | // Rename |
||
| 124 | if(file_exists(app_path("CBPlugins/".$key))) rrmdir(app_path("CBPlugins/".$key)); |
||
| 125 | rename(app_path("CBPlugins/".$dirName), app_path("CBPlugins/".$key)); |
||
| 126 | |||
| 127 | // Read Plugin JSON |
||
| 128 | $pluginJson = json_decode(file_get_contents(app_path("CBPlugins/".$key."/plugin.json")), true); |
||
| 129 | |||
| 130 | // Check if has asset |
||
| 131 | if($pluginJson && $pluginJson['asset']) { |
||
| 132 | // Check destination folder is ready |
||
| 133 | if(file_exists(public_path("cb_asset/".$key))) { |
||
| 134 | rrmdir(public_path("cb_asset/".$key)); |
||
| 135 | } |
||
| 136 | |||
| 137 | // Create directory empty |
||
| 138 | mkdir(public_path("cb_asset/".$key)); |
||
| 139 | |||
| 140 | // Copy asset |
||
| 141 | $this->recursiveCopy(app_path("CBPlugins/".$key."/".$pluginJson['asset']), public_path("cb_asset/".$key)); |
||
| 142 | } |
||
| 143 | |||
| 144 | //Migrate |
||
| 145 | Artisan::call("migrate"); |
||
| 146 | |||
| 147 | return response()->json(['status'=>true,'message'=>'Install / update plugin has been succesfull!']); |
||
| 148 | |||
| 149 | } else { |
||
| 150 | return response()->json(['status'=>false,'message'=>"Failed to install/update, can't open the plugin archive"]); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | }else{ |
||
| 155 | return response()->json(['status'=>false,'message'=>'Failed to install/update, plugin key is not found']); |
||
| 156 | } |
||
| 157 | } catch (\Exception $e) { |
||
| 158 | return response()->json(['status'=>false,'message'=>'Something went wrong!']); |
||
| 159 | } |
||
| 204 | } |
If you suppress an error, we recommend checking for the error condition explicitly: