| Total Complexity | 41 |
| Total Lines | 224 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
Complex classes like DeveloperPluginStoreController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use DeveloperPluginStoreController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 20 | class DeveloperPluginStoreController extends Controller |
||
| 21 | { |
||
| 22 | |||
| 23 | private $view = "crudbooster::dev_layouts.modules.plugin"; |
||
| 24 | |||
| 25 | public function __construct() |
||
| 28 | } |
||
| 29 | |||
| 30 | |||
| 31 | public function getIndex() { |
||
| 32 | |||
| 33 | if(request("refresh")) { |
||
| 34 | $this->fetchPluginData(false ); |
||
| 35 | return cb()->redirectBack("Plugin list has been refreshed!","success"); |
||
| 36 | } |
||
| 37 | |||
| 38 | $data = []; |
||
| 39 | $data['result'] = $this->fetchPluginData(); |
||
| 40 | return view($this->view.'.index',$data); |
||
| 41 | } |
||
| 42 | |||
| 43 | public function postLoginAccount() { |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | public function postRequestBuyPlugin() { |
||
| 87 | } |
||
| 88 | } |
||
| 89 | |||
| 90 | public function getUninstall($key) |
||
| 91 | { |
||
| 92 | $pluginData = $this->fetchPluginData(); |
||
| 93 | |||
| 94 | if(isset($pluginData[$key])) { |
||
| 95 | if(file_exists(app_path("CBPlugins/".$key))) { |
||
| 96 | |||
| 97 | if(isset($pluginData['source']) && $pluginData['source'] == 'composer') { |
||
| 98 | if(isset($pluginData['package'])) { |
||
| 99 | ComposerHelper::composerRemove($pluginData['package']); |
||
| 100 | } |
||
| 101 | } |
||
| 102 | |||
| 103 | rrmdir(app_path("CBPlugins/".$key)); |
||
| 104 | |||
| 105 | return response()->json(['status'=>true, 'message'=>'Plugin has been uninstalled!']); |
||
| 106 | }else{ |
||
| 107 | return response()->json(['status'=>false,'message'=>'Failed to uninstall, plugin is not found']); |
||
| 108 | } |
||
| 109 | }else { |
||
| 110 | return response()->json(['status'=>false,'message'=>'Failed to uninstall, plugin key is not found']); |
||
| 111 | } |
||
| 112 | } |
||
| 113 | |||
| 114 | private function recursiveCopy($src,$dst) { |
||
| 115 | $dir = opendir($src); |
||
| 116 | @mkdir($dst); |
||
| 117 | while(false !== ( $file = readdir($dir)) ) { |
||
| 118 | if (( $file != '.' ) && ( $file != '..' )) { |
||
| 119 | if ( is_dir($src . '/' . $file) ) { |
||
| 120 | $this->recursiveCopy($src . '/' . $file,$dst . '/' . $file); |
||
| 121 | } |
||
| 122 | else { |
||
| 123 | copy($src . '/' . $file,$dst . '/' . $file); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | closedir($dir); |
||
| 128 | } |
||
| 129 | |||
| 130 | public function getInstall($key) |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | private function fetchPluginData($cache = true) |
||
| 244 | } |
||
| 245 | } |