Conditions | 10 |
Paths | 160 |
Total Lines | 51 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
79 | public static function list() |
||
80 | { |
||
81 | $ret=[]; |
||
82 | $marketspaceRaw=self::getRemote(); |
||
83 | if(empty($marketspaceRaw)) return []; |
||
84 | foreach($marketspaceRaw["packages"] as $extension){ |
||
85 | $temp=[ |
||
86 | "details"=>$extension, |
||
87 | "status"=>0, |
||
88 | "version"=>null, |
||
89 | "updatable"=>false, |
||
90 | "settings"=>null, |
||
91 | "available"=>null |
||
92 | ]; |
||
93 | $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge"?"VirtualJudge":"OnlineJudge"; |
||
94 | try { |
||
95 | try { |
||
96 | $BabelConfig=json_decode(file_get_contents(babel_path("Extension/{$extension['code']}/babel.json")), true); |
||
97 | }catch (Throwable $e){ |
||
98 | $BabelConfig=[]; |
||
99 | } |
||
100 | if (!empty($BabelConfig)) { |
||
101 | if ($BabelConfig["version"]=='__cur__') { |
||
102 | $BabelConfig["version"]=explode("-", version())[0]; |
||
103 | } |
||
104 | $downloadedVersion=new Version($BabelConfig["version"]); |
||
105 | $remoteVersion=new Version($extension["version"]); |
||
106 | $temp["updatable"]=$remoteVersion->isGreaterThan($downloadedVersion); |
||
107 | |||
108 | $installedConfig=OJModel::where(["ocode"=>$extension["code"]])->first(); |
||
109 | if (is_null($installedConfig)){ |
||
110 | $temp["status"]=1; |
||
111 | } else { |
||
112 | $temp["version"]=$installedConfig->version; // local installed version |
||
113 | $installedVersion=new Version($temp["version"]); |
||
114 | if ($downloadedVersion->isGreaterThan($installedVersion)){ |
||
115 | $temp["status"]=1; |
||
116 | } else { |
||
117 | $temp["status"]=2; |
||
118 | } |
||
119 | $temp["settings"]=false; |
||
120 | $temp["available"]=$installedConfig->status; |
||
121 | } |
||
122 | } |
||
123 | }catch (Throwable $e){ |
||
124 | continue; |
||
125 | } |
||
126 | $ret[]=$temp; |
||
127 | } |
||
128 | |||
129 | return $ret; |
||
130 | } |
||
164 |