| 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 |
||
| 20 | public static function list() |
||
| 21 | { |
||
| 22 | $ret=[]; |
||
| 23 | $marketspaceRaw=self::getRemote(); |
||
| 24 | if(empty($marketspaceRaw)) return []; |
||
| 25 | foreach($marketspaceRaw["packages"] as $extension){ |
||
| 26 | $temp=[ |
||
| 27 | "details"=>$extension, |
||
| 28 | "status"=>0, |
||
| 29 | "version"=>null, |
||
| 30 | "updatable"=>false, |
||
| 31 | "settings"=>null, |
||
| 32 | "available"=>null |
||
| 33 | ]; |
||
| 34 | $temp["details"]["typeParsed"]=$temp["details"]["type"]=="virtual-judge"?"VirtualJudge":"OnlineJudge"; |
||
| 35 | try { |
||
| 36 | try { |
||
| 37 | $BabelConfig=json_decode(file_get_contents(babel_path("Extension/{$extension['code']}/babel.json")), true); |
||
| 38 | }catch (Throwable $e){ |
||
| 39 | $BabelConfig=[]; |
||
| 40 | } |
||
| 41 | if (!empty($BabelConfig)) { |
||
| 42 | if ($BabelConfig["version"]=='__cur__') { |
||
| 43 | $BabelConfig["version"]=explode("-", version())[0]; |
||
| 44 | } |
||
| 45 | $downloadedVersion=new Version($BabelConfig["version"]); |
||
| 46 | $remoteVersion=new Version($extension["version"]); |
||
| 47 | $temp["updatable"]=$remoteVersion->isGreaterThan($downloadedVersion); |
||
| 48 | |||
| 49 | $installedConfig=OJModel::where(["ocode"=>$extension["code"]])->first(); |
||
| 50 | if (is_null($installedConfig)){ |
||
| 51 | $temp["status"]=1; |
||
| 52 | } else { |
||
| 53 | $temp["version"]=$installedConfig->version; // local installed version |
||
| 54 | $installedVersion=new Version($temp["version"]); |
||
| 55 | if ($downloadedVersion->isGreaterThan($installedVersion)){ |
||
| 56 | $temp["status"]=1; |
||
| 57 | } else { |
||
| 58 | $temp["status"]=2; |
||
| 59 | } |
||
| 60 | $temp["settings"]=false; |
||
| 61 | $temp["available"]=$installedConfig->status; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | }catch (Throwable $e){ |
||
| 65 | $temp["status"]=-1; |
||
| 66 | } |
||
| 67 | $ret[]=$temp; |
||
| 68 | } |
||
| 69 | |||
| 70 | return $ret; |
||
| 71 | } |
||
| 82 |