Conditions | 17 |
Paths | 64 |
Total Lines | 76 |
Code Lines | 59 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
41 | public function handle() |
||
42 | { |
||
43 | $extension=$this->argument('extension'); |
||
44 | $exception=$this->option('exception'); |
||
45 | $ignoreReqs=$this->option('ignore-platform-reqs'); |
||
46 | $output=new BufferedOutput(); |
||
47 | if (is_dir(babel_path("Extension/$extension/"))) { |
||
48 | if (!$exception) { |
||
49 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>An extension named <fg=green>$extension</> already took place, did you mean <fg=green>php artisan bable:update $extension</>?</>\n"); |
||
50 | } else { |
||
51 | throw new Exception("\n <bg=red;fg=white> Exception </> : <fg=yellow>An extension named <fg=green>$extension</> already took place, did you mean <fg=green>php artisan bable:update $extension</>?</>\n"); |
||
52 | } |
||
53 | return; |
||
54 | } |
||
55 | $marketspaceRaw=json_decode(file_get_contents(config('babel.mirror')."/babel.json"), true); |
||
56 | $marketspacePackages=$marketspaceRaw["packages"]; |
||
57 | $marketspaceHash=$marketspaceRaw["content-hash"]; |
||
|
|||
58 | $packageCodeColumn=array_column($marketspacePackages, 'code'); |
||
59 | $targetPackage=$marketspacePackages[array_search($extension, $packageCodeColumn)]; |
||
60 | // if(!isset($targetPackage["downloadURL"]) || trim($targetPackage["downloadURL"])=="" || is_null($targetPackage["downloadURL"])){ |
||
61 | if (!isset($targetPackage["downloadURL"]) || !is_array($targetPackage["downloadURL"]) || is_null($targetPackage["downloadURL"]) || !isset($targetPackage["downloadURL"][0]["url"]) || trim($targetPackage["downloadURL"][0]["url"])=="" || is_null($targetPackage["downloadURL"][0]["url"])) { |
||
62 | if (!$exception) { |
||
63 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n"); |
||
64 | } else { |
||
65 | throw new Exception("\n <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n"); |
||
66 | } |
||
67 | return; |
||
68 | } |
||
69 | //todo: check requirements |
||
70 | $this->line("Downloading <fg=green>$extension</>(<fg=yellow>{$targetPackage['version']}</>)"); |
||
71 | $filename="$extension-".basename($targetPackage["downloadURL"][0]["url"]); |
||
72 | file_put_contents(babel_path("Tmp/$filename"), file_get_contents($targetPackage["downloadURL"][0]["url"])); |
||
73 | // unzip |
||
74 | if (!is_dir(babel_path("Tmp/$extension/"))) { |
||
75 | mkdir(babel_path("Tmp/$extension/"), 0777, true); |
||
76 | } |
||
77 | try { |
||
78 | $zipFile=new ZipFile(); |
||
79 | $zipFile->openFile(babel_path("Tmp/$filename"))->extractTo(babel_path("Tmp/$extension/"))->close(); |
||
80 | $babelPath=glob_recursive(babel_path("Tmp/$extension/babel.json")); |
||
81 | if (empty($babelPath)) { |
||
82 | if (!$exception) { |
||
83 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>There exists no <fg=green>babel.json</> files.</>\n"); |
||
84 | } else { |
||
85 | throw new Exception("\n <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n"); |
||
86 | } |
||
87 | return; |
||
88 | } else { |
||
89 | $babelPath=dirname($babelPath[0]); |
||
90 | // if(is_dir(babel_path("Extension/$extension/"))) mkdir(babel_path("Extension/$extension/")); |
||
91 | rename($babelPath, babel_path("Extension/$extension/")); |
||
92 | } |
||
93 | } catch (\PhpZip\Exception\ZipException $e) { |
||
94 | $this->postProc($filename, $extension); |
||
95 | if (!$exception) { |
||
96 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n"); |
||
97 | } else { |
||
98 | throw new Exception("\n <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n"); |
||
99 | } |
||
100 | return; |
||
101 | } catch (Exception $e) { |
||
102 | $this->postProc($filename, $extension); |
||
103 | if (!$exception) { |
||
104 | $this->line("\n <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n"); |
||
105 | } else { |
||
106 | throw new Exception("\n <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n"); |
||
107 | } |
||
108 | return; |
||
109 | } |
||
110 | $this->postProc($filename, $extension); |
||
111 | $this->line("Downloaded <fg=green>$extension</>(<fg=yellow>{$targetPackage['version']}</>)"); |
||
112 | $this->call("babel:install", [ |
||
113 | 'extension' => $extension, |
||
114 | '--ignore-platform-reqs' => $ignoreReqs, |
||
115 | ]); |
||
116 | $output->fetch(); |
||
117 | } |
||
142 |