Passed
Pull Request — master (#216)
by Chenyi
04:17
created
app/Http/Middleware/Privileged.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -18,16 +18,16 @@
 block discarded – undo
18 18
     public function handle($request, Closure $next)
19 19
     {
20 20
         if (Auth::check()) {
21
-            if(isset($request->gcode)){
21
+            if (isset($request->gcode)) {
22 22
                 //group privilege
23 23
                 $groupModel=new GroupModel();
24
-                if($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2){
24
+                if ($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2) {
25 25
                     return $next($request);
26 26
                 }
27
-            }elseif(isset($request->cid)) {
27
+            }elseif (isset($request->cid)) {
28 28
                 //contest privilege
29 29
                 $contestModel=new ContestModel();
30
-                if($contestModel->judgeClearance($request->cid, Auth::user()->id)==3){
30
+                if ($contestModel->judgeClearance($request->cid, Auth::user()->id)==3) {
31 31
                     return $next($request);
32 32
                 }
33 33
             }
Please login to merge, or discard this patch.
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
                 if($groupModel->judgeClearance($groupModel->gid($request->gcode), Auth::user()->id)>=2){
25 25
                     return $next($request);
26 26
                 }
27
-            }elseif(isset($request->cid)) {
27
+            } elseif(isset($request->cid)) {
28 28
                 //contest privilege
29 29
                 $contestModel=new ContestModel();
30 30
                 if($contestModel->judgeClearance($request->cid, Auth::user()->id)==3){
Please login to merge, or discard this patch.
app/Console/Commands/Babel/Install.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@
 block discarded – undo
45 45
         $installerProvider="Installer";
46 46
         try {
47 47
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true);
48
-        }catch(Exception $e){
48
+        } catch(Exception $e){
49 49
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>babel.json parse error, The extension may not exist.</>\n");
50 50
             if($this->confirm("Would you like to download it from the marketspace first?")){
51 51
                 $this->call("babel:require", ['extension' => $extension]);
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var string
16 16
      */
17
-    protected $signature = 'babel:install {extension : The package name of the extension} {--ignore-platform-reqs : Ignore the Platform Requirements when install}';
17
+    protected $signature='babel:install {extension : The package name of the extension} {--ignore-platform-reqs : Ignore the Platform Requirements when install}';
18 18
 
19 19
     /**
20 20
      * The console command description.
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $description = 'Install a given Babel Extension to NOJ';
24
+    protected $description='Install a given Babel Extension to NOJ';
25 25
 
26 26
     /**
27 27
      * Create a new command instance.
@@ -40,36 +40,36 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle()
42 42
     {
43
-        $extension = $this->argument('extension');
44
-        $ignoreReqs = $this->option('ignore-platform-reqs');
45
-        $output = new BufferedOutput();
43
+        $extension=$this->argument('extension');
44
+        $ignoreReqs=$this->option('ignore-platform-reqs');
45
+        $output=new BufferedOutput();
46 46
         $installerProvider="Installer";
47 47
         try {
48 48
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true);
49
-        }catch(Exception $e){
49
+        } catch (Exception $e) {
50 50
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>babel.json parse error, The extension may not exist.</>\n");
51
-            if($this->confirm("Would you like to download it from the marketspace first?")){
51
+            if ($this->confirm("Would you like to download it from the marketspace first?")) {
52 52
                 $this->call("babel:require", ['extension' => $extension]);
53 53
                 $output->fetch();
54 54
             }
55 55
             return;
56 56
         }
57
-        if(!isset($BabelConfig["provider"]["installer"]) || trim($BabelConfig["provider"]["installer"])=="" || is_null($BabelConfig["provider"]["installer"])){
57
+        if (!isset($BabelConfig["provider"]["installer"]) || trim($BabelConfig["provider"]["installer"])=="" || is_null($BabelConfig["provider"]["installer"])) {
58 58
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>Installer not provided.</>\n");
59 59
             return;
60 60
         }
61 61
         $installerProvider=$BabelConfig["provider"]["installer"];
62
-        $installer=self::create($extension,$installerProvider,$this);
63
-        if(!is_null($installer)) {
62
+        $installer=self::create($extension, $installerProvider, $this);
63
+        if (!is_null($installer)) {
64 64
             $installer->install();
65 65
         } else {
66 66
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>Installer initiation error.</>\n");
67 67
         }
68 68
     }
69 69
 
70
-    public static function create($oj,$installerProvider,$class) {
71
-        $className = "App\\Babel\\Extension\\$oj\\$installerProvider";
72
-        if(class_exists($className)) {
70
+    public static function create($oj, $installerProvider, $class) {
71
+        $className="App\\Babel\\Extension\\$oj\\$installerProvider";
72
+        if (class_exists($className)) {
73 73
             return new $className($class);
74 74
         } else {
75 75
             return null;
Please login to merge, or discard this patch.
app/Console/Commands/Babel/Update.php 2 patches
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var string
16 16
      */
17
-    protected $signature = 'babel:update {extension : The package name of the extension}';
17
+    protected $signature='babel:update {extension : The package name of the extension}';
18 18
 
19 19
     /**
20 20
      * The console command description.
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $description = 'Update a given Babel Extension to NOJ';
24
+    protected $description='Update a given Babel Extension to NOJ';
25 25
 
26 26
     /**
27 27
      * Create a new command instance.
@@ -40,14 +40,14 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle()
42 42
     {
43
-        $extension = $this->argument('extension');
44
-        $output = new BufferedOutput();
43
+        $extension=$this->argument('extension');
44
+        $output=new BufferedOutput();
45 45
         $this->line("Updating <fg=green>$extension</>");
46 46
         try {
47 47
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true);
48
-        }catch(Exception $e){
48
+        } catch (Exception $e) {
49 49
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>babel.json parse error, The extension may not exist.</>\n");
50
-            if($this->confirm("Would you like to download it from the marketspace first?")){
50
+            if ($this->confirm("Would you like to download it from the marketspace first?")) {
51 51
                 $this->call("babel:require", ['extension' => $extension]);
52 52
                 $output->fetch();
53 53
             }
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
             $output->fetch();
61 61
             $this->delDir(babel_path("Tmp/backup/$extension/"));
62 62
             $this->line("Updated <fg=green>$extension</>");
63
-        } catch(Exception $e) {
63
+        } catch (Exception $e) {
64 64
             $this->line($e->getMessage());
65 65
             $this->roolbackBackup(($extension));
66 66
         }
@@ -68,23 +68,23 @@  discard block
 block discarded – undo
68 68
 
69 69
     private function backup($extension)
70 70
     {
71
-        if(!is_dir(babel_path("Tmp/backup/"))) mkdir(babel_path("Tmp/backup/"));
72
-        if(is_dir(babel_path("Tmp/backup/$extension/"))) $this->delDir(babel_path("Tmp/backup/$extension/"));
71
+        if (!is_dir(babel_path("Tmp/backup/"))) mkdir(babel_path("Tmp/backup/"));
72
+        if (is_dir(babel_path("Tmp/backup/$extension/"))) $this->delDir(babel_path("Tmp/backup/$extension/"));
73 73
         rename(babel_path("Extension/$extension/"), babel_path("Tmp/backup/$extension/"));
74 74
     }
75 75
 
76 76
     private function roolbackBackup($extension)
77 77
     {
78
-        if(is_dir(babel_path("Extension/$extension/"))) $this->delDir(babel_path("Extension/$extension/"));
78
+        if (is_dir(babel_path("Extension/$extension/"))) $this->delDir(babel_path("Extension/$extension/"));
79 79
         rename(babel_path("Tmp/backup/$extension/"), babel_path("Extension/$extension/"));
80 80
     }
81 81
 
82
-    private function delDir($dir){
83
-        if(!is_dir($dir)) return;
84
-        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
85
-        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
86
-        foreach($files as $file) {
87
-            if ($file->isDir()){
82
+    private function delDir($dir) {
83
+        if (!is_dir($dir)) return;
84
+        $it=new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
85
+        $files=new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
86
+        foreach ($files as $file) {
87
+            if ($file->isDir()) {
88 88
                 rmdir($file->getRealPath());
89 89
             } else {
90 90
                 unlink($file->getRealPath());
Please login to merge, or discard this patch.
Braces   +13 added lines, -5 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
         $this->line("Updating <fg=green>$extension</>");
46 46
         try {
47 47
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$extension/babel.json")), true);
48
-        }catch(Exception $e){
48
+        } catch(Exception $e){
49 49
             $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>babel.json parse error, The extension may not exist.</>\n");
50 50
             if($this->confirm("Would you like to download it from the marketspace first?")){
51 51
                 $this->call("babel:require", ['extension' => $extension]);
@@ -68,19 +68,27 @@  discard block
 block discarded – undo
68 68
 
69 69
     private function backup($extension)
70 70
     {
71
-        if(!is_dir(babel_path("Tmp/backup/"))) mkdir(babel_path("Tmp/backup/"));
72
-        if(is_dir(babel_path("Tmp/backup/$extension/"))) $this->delDir(babel_path("Tmp/backup/$extension/"));
71
+        if(!is_dir(babel_path("Tmp/backup/"))) {
72
+            mkdir(babel_path("Tmp/backup/"));
73
+        }
74
+        if(is_dir(babel_path("Tmp/backup/$extension/"))) {
75
+            $this->delDir(babel_path("Tmp/backup/$extension/"));
76
+        }
73 77
         rename(babel_path("Extension/$extension/"), babel_path("Tmp/backup/$extension/"));
74 78
     }
75 79
 
76 80
     private function roolbackBackup($extension)
77 81
     {
78
-        if(is_dir(babel_path("Extension/$extension/"))) $this->delDir(babel_path("Extension/$extension/"));
82
+        if(is_dir(babel_path("Extension/$extension/"))) {
83
+            $this->delDir(babel_path("Extension/$extension/"));
84
+        }
79 85
         rename(babel_path("Tmp/backup/$extension/"), babel_path("Extension/$extension/"));
80 86
     }
81 87
 
82 88
     private function delDir($dir){
83
-        if(!is_dir($dir)) return;
89
+        if(!is_dir($dir)) {
90
+            return;
91
+        }
84 92
         $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
85 93
         $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
86 94
         foreach($files as $file) {
Please login to merge, or discard this patch.
app/Console/Commands/Babel/Crawl.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var string
16 16
      */
17
-    protected $signature = 'babel:crawl {extension : The package name of the extension} {--action=crawl_problem : The action of the Crawler} {--con=all : The target problemset of the Crawler} {--cached : Whether cached or not}';
17
+    protected $signature='babel:crawl {extension : The package name of the extension} {--action=crawl_problem : The action of the Crawler} {--con=all : The target problemset of the Crawler} {--cached : Whether cached or not}';
18 18
 
19 19
     /**
20 20
      * The console command description.
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $description = 'Crawl problems for a given Babel Extension to NOJ';
24
+    protected $description='Crawl problems for a given Babel Extension to NOJ';
25 25
 
26 26
     /**
27 27
      * Create a new command instance.
@@ -40,10 +40,10 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle()
42 42
     {
43
-        $extension = $this->argument('extension');
44
-        $action = $this->option('action');
45
-        $con = $this->option('con');
46
-        $cached = $this->option('cached');
43
+        $extension=$this->argument('extension');
44
+        $action=$this->option('action');
45
+        $con=$this->option('con');
46
+        $cached=$this->option('cached');
47 47
         $babel=new Babel();
48 48
         $babel->crawl([
49 49
             "name" => $extension,
Please login to merge, or discard this patch.
app/Console/Commands/Babel/BabelRequire.php 2 patches
Spacing   +30 added lines, -30 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var string
16 16
      */
17
-    protected $signature = 'babel:require {extension : The package name of the extension} {--exception}';
17
+    protected $signature='babel:require {extension : The package name of the extension} {--exception}';
18 18
 
19 19
     /**
20 20
      * The console command description.
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $description = 'Download a given Babel Extension to NOJ';
24
+    protected $description='Download a given Babel Extension to NOJ';
25 25
 
26 26
     /**
27 27
      * Create a new command instance.
@@ -40,77 +40,77 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle()
42 42
     {
43
-        $extension = $this->argument('extension');
44
-        $exception = $this->option('exception');
45
-        $output = new BufferedOutput();
46
-        if(is_dir(babel_path("Extension/$extension/"))) {
47
-            if(!$exception) $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");
43
+        $extension=$this->argument('extension');
44
+        $exception=$this->option('exception');
45
+        $output=new BufferedOutput();
46
+        if (is_dir(babel_path("Extension/$extension/"))) {
47
+            if (!$exception) $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");
48 48
             else 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");
49 49
             return;
50 50
         }
51
-        $marketspaceRaw=json_decode(file_get_contents(env("BABEL_MIRROR","https://acm.njupt.edu.cn/babel")."/babel.json"),true);
51
+        $marketspaceRaw=json_decode(file_get_contents(env("BABEL_MIRROR", "https://acm.njupt.edu.cn/babel")."/babel.json"), true);
52 52
         $marketspacePackages=$marketspaceRaw["packages"];
53 53
         $marketspaceHash=$marketspaceRaw["content-hash"];
54 54
         $packageCodeColumn=array_column($marketspacePackages, 'code');
55 55
         $targetPackage=$marketspacePackages[array_search($extension, $packageCodeColumn)];
56 56
         // if(!isset($targetPackage["downloadURL"]) || trim($targetPackage["downloadURL"])=="" || is_null($targetPackage["downloadURL"])){
57
-        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"])){
58
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
57
+        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"])) {
58
+            if (!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
59 59
             else throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
60 60
             return;
61 61
         }
62 62
         //todo: check requirements
63 63
         $this->line("Downloading <fg=green>$extension</>(<fg=yellow>{$targetPackage['version']}</>)");
64 64
         $filename="$extension-".basename($targetPackage["downloadURL"][0]["url"]);
65
-        file_put_contents(babel_path("Tmp/$filename"),file_get_contents($targetPackage["downloadURL"][0]["url"]));
65
+        file_put_contents(babel_path("Tmp/$filename"), file_get_contents($targetPackage["downloadURL"][0]["url"]));
66 66
         // unzip
67
-        if(!is_dir(babel_path("Tmp/$extension/"))) mkdir(babel_path("Tmp/$extension/"));
67
+        if (!is_dir(babel_path("Tmp/$extension/"))) mkdir(babel_path("Tmp/$extension/"));
68 68
         try {
69
-            $zipFile = new ZipFile();
69
+            $zipFile=new ZipFile();
70 70
             $zipFile->openFile(babel_path("Tmp/$filename"))->extractTo(babel_path("Tmp/$extension/"))->close();
71 71
             $babelPath=glob_recursive(babel_path("Tmp/$extension/babel.json"));
72
-            if(empty($babelPath)){
73
-                if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>There exists no <fg=green>babel.json</> files.</>\n");
72
+            if (empty($babelPath)) {
73
+                if (!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>There exists no <fg=green>babel.json</> files.</>\n");
74 74
                 else throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
75 75
                 return;
76 76
             } else {
77 77
                 $babelPath=dirname($babelPath[0]);
78 78
                 // if(is_dir(babel_path("Extension/$extension/"))) mkdir(babel_path("Extension/$extension/"));
79
-                rename($babelPath,babel_path("Extension/$extension/"));
79
+                rename($babelPath, babel_path("Extension/$extension/"));
80 80
             }
81
-        } catch(\PhpZip\Exception\ZipException $e) {
82
-            $this->postProc($filename,$extension);
83
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
81
+        } catch (\PhpZip\Exception\ZipException $e) {
82
+            $this->postProc($filename, $extension);
83
+            if (!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
84 84
             else {
85 85
                 throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
86 86
             }
87 87
             return;
88
-        } catch(Exception $e){
89
-            $this->postProc($filename,$extension);
90
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
88
+        } catch (Exception $e) {
89
+            $this->postProc($filename, $extension);
90
+            if (!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
91 91
             else {
92 92
                 throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
93 93
             }
94 94
             return;
95 95
         }
96
-        $this->postProc($filename,$extension);
96
+        $this->postProc($filename, $extension);
97 97
         $this->line("Downloaded <fg=green>$extension</>(<fg=yellow>{$targetPackage['version']}</>)");
98 98
         $this->call("babel:install", ['extension' => $extension]);
99 99
         $output->fetch();
100 100
     }
101 101
 
102
-    private function postProc($filename,$extension)
102
+    private function postProc($filename, $extension)
103 103
     {
104 104
         unlink(babel_path("Tmp/$filename"));
105 105
         $this->delDir(babel_path("Tmp/$extension/"));
106 106
     }
107 107
 
108
-    private function delDir($dir){
109
-        if(!is_dir($dir)) return;
110
-        $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
111
-        $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
112
-        foreach($files as $file) {
113
-            if ($file->isDir()){
108
+    private function delDir($dir) {
109
+        if (!is_dir($dir)) return;
110
+        $it=new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
111
+        $files=new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
112
+        foreach ($files as $file) {
113
+            if ($file->isDir()) {
114 114
                 rmdir($file->getRealPath());
115 115
             } else {
116 116
                 unlink($file->getRealPath());
Please login to merge, or discard this patch.
Braces   +27 added lines, -12 removed lines patch added patch discarded remove patch
@@ -44,8 +44,11 @@  discard block
 block discarded – undo
44 44
         $exception = $this->option('exception');
45 45
         $output = new BufferedOutput();
46 46
         if(is_dir(babel_path("Extension/$extension/"))) {
47
-            if(!$exception) $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");
48
-            else 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");
47
+            if(!$exception) {
48
+                $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");
49
+            } else {
50
+                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");
51
+            }
49 52
             return;
50 53
         }
51 54
         $marketspaceRaw=json_decode(file_get_contents(env("BABEL_MIRROR","https://acm.njupt.edu.cn/babel")."/babel.json"),true);
@@ -55,8 +58,11 @@  discard block
 block discarded – undo
55 58
         $targetPackage=$marketspacePackages[array_search($extension, $packageCodeColumn)];
56 59
         // if(!isset($targetPackage["downloadURL"]) || trim($targetPackage["downloadURL"])=="" || is_null($targetPackage["downloadURL"])){
57 60
         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"])){
58
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
59
-            else throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
61
+            if(!$exception) {
62
+                $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
63
+            } else {
64
+                throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
65
+            }
60 66
             return;
61 67
         }
62 68
         //todo: check requirements
@@ -64,14 +70,19 @@  discard block
 block discarded – undo
64 70
         $filename="$extension-".basename($targetPackage["downloadURL"][0]["url"]);
65 71
         file_put_contents(babel_path("Tmp/$filename"),file_get_contents($targetPackage["downloadURL"][0]["url"]));
66 72
         // unzip
67
-        if(!is_dir(babel_path("Tmp/$extension/"))) mkdir(babel_path("Tmp/$extension/"));
73
+        if(!is_dir(babel_path("Tmp/$extension/"))) {
74
+            mkdir(babel_path("Tmp/$extension/"));
75
+        }
68 76
         try {
69 77
             $zipFile = new ZipFile();
70 78
             $zipFile->openFile(babel_path("Tmp/$filename"))->extractTo(babel_path("Tmp/$extension/"))->close();
71 79
             $babelPath=glob_recursive(babel_path("Tmp/$extension/babel.json"));
72 80
             if(empty($babelPath)){
73
-                if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>There exists no <fg=green>babel.json</> files.</>\n");
74
-                else throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
81
+                if(!$exception) {
82
+                    $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>There exists no <fg=green>babel.json</> files.</>\n");
83
+                } else {
84
+                    throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>No available download link.</>\n");
85
+                }
75 86
                 return;
76 87
             } else {
77 88
                 $babelPath=dirname($babelPath[0]);
@@ -80,15 +91,17 @@  discard block
 block discarded – undo
80 91
             }
81 92
         } catch(\PhpZip\Exception\ZipException $e) {
82 93
             $this->postProc($filename,$extension);
83
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
84
-            else {
94
+            if(!$exception) {
95
+                $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
96
+            } else {
85 97
                 throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
86 98
             }
87 99
             return;
88 100
         } catch(Exception $e){
89 101
             $this->postProc($filename,$extension);
90
-            if(!$exception) $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
91
-            else {
102
+            if(!$exception) {
103
+                $this->line("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
104
+            } else {
92 105
                 throw new Exception("\n  <bg=red;fg=white> Exception </> : <fg=yellow>An error occoured when extract <fg=green>$extension</>.</>\n");
93 106
             }
94 107
             return;
@@ -106,7 +119,9 @@  discard block
 block discarded – undo
106 119
     }
107 120
 
108 121
     private function delDir($dir){
109
-        if(!is_dir($dir)) return;
122
+        if(!is_dir($dir)) {
123
+            return;
124
+        }
110 125
         $it = new \RecursiveDirectoryIterator($dir, \RecursiveDirectoryIterator::SKIP_DOTS);
111 126
         $files = new \RecursiveIteratorIterator($it, \RecursiveIteratorIterator::CHILD_FIRST);
112 127
         foreach($files as $file) {
Please login to merge, or discard this patch.
app/Console/Commands/Babel/Uninstall.php 2 patches
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@  discard block
 block discarded – undo
12 12
      *
13 13
      * @var string
14 14
      */
15
-    protected $signature = 'babel:uninstall {extension : The package name of the extension}';
15
+    protected $signature='babel:uninstall {extension : The package name of the extension}';
16 16
 
17 17
     /**
18 18
      * The console command description.
19 19
      *
20 20
      * @var string
21 21
      */
22
-    protected $description = 'Uninstall a given Babel Extension to NOJ';
22
+    protected $description='Uninstall a given Babel Extension to NOJ';
23 23
 
24 24
     /**
25 25
      * Create a new command instance.
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
      */
39 39
     public function handle()
40 40
     {
41
-        $extension = $this->argument('extension');
42
-        $submitter=self::create($extension,$this);
43
-        if(!is_null($submitter)) $submitter->uninstall();
41
+        $extension=$this->argument('extension');
42
+        $submitter=self::create($extension, $this);
43
+        if (!is_null($submitter)) $submitter->uninstall();
44 44
         else throw new Exception("Uninstaller Not Provided");
45 45
     }
46 46
 
47
-    public static function create($oj,$class) {
47
+    public static function create($oj, $class) {
48 48
         $installerProvider="Installer";
49 49
         try {
50 50
             $BabelConfig=json_decode(file_get_contents(babel_path("Extension/$oj/babel.json")), true);
51 51
             $installerProvider=$BabelConfig["provider"]["installer"];
52
-        } catch(ErrorException $e) {
53
-        } catch(Exception $e) {
52
+        } catch (ErrorException $e) {
53
+        } catch (Exception $e) {
54 54
         }
55
-        $className = "App\\Babel\\Extension\\$oj\\$installerProvider";
56
-        if(class_exists($className)) {
55
+        $className="App\\Babel\\Extension\\$oj\\$installerProvider";
56
+        if (class_exists($className)) {
57 57
             return new $className($class);
58 58
         } else {
59 59
             return null;
Please login to merge, or discard this patch.
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -40,8 +40,11 @@
 block discarded – undo
40 40
     {
41 41
         $extension = $this->argument('extension');
42 42
         $submitter=self::create($extension,$this);
43
-        if(!is_null($submitter)) $submitter->uninstall();
44
-        else throw new Exception("Uninstaller Not Provided");
43
+        if(!is_null($submitter)) {
44
+            $submitter->uninstall();
45
+        } else {
46
+            throw new Exception("Uninstaller Not Provided");
47
+        }
45 48
     }
46 49
 
47 50
     public static function create($oj,$class) {
Please login to merge, or discard this patch.
app/Models/AnnouncementModel.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@
 block discarded – undo
17 17
 
18 18
     public function fetch()
19 19
     {
20
-        $list=DB::table($this->table)->orderBy('post_date','desc')->get()->all();
20
+        $list=DB::table($this->table)->orderBy('post_date', 'desc')->get()->all();
21 21
         if (empty($list)) {
22 22
             return [];
23 23
         }
Please login to merge, or discard this patch.
app/Models/RankModel.php 2 patches
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use Illuminate\Support\Facades\DB;
8 8
 use Illuminate\Support\Arr;
9 9
 use App\Models\Rating\RatingCalculator;
10
-use Cache,Redis;
10
+use Cache, Redis;
11 11
 
12 12
 class RankModel extends Model
13 13
 {
@@ -65,28 +65,28 @@  discard block
 block discarded – undo
65 65
 
66 66
     public static function getColor($rankTitle)
67 67
     {
68
-        if(is_null($rankTitle)) return "";
68
+        if (is_null($rankTitle)) return "";
69 69
         return self::$casualRanking[$rankTitle];
70 70
     }
71 71
 
72 72
     public static function getProfessionalColor($rankTitle)
73 73
     {
74
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
74
+        if (is_null($rankTitle)) return self::$professionalRanking["None"];
75 75
         return self::$professionalRanking[$rankTitle];
76 76
     }
77 77
 
78 78
     public function list($num)
79 79
     {
80 80
         $rankList=Cache::tags(['rank'])->get('general');
81
-        if($rankList==null) $rankList=[];
82
-        $rankList=array_slice($rankList,0,$num);
83
-        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all();
81
+        if ($rankList==null) $rankList=[];
82
+        $rankList=array_slice($rankList, 0, $num);
83
+        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all();
84 84
         $userInfo=[];
85
-        foreach($userInfoRaw as $u){
85
+        foreach ($userInfoRaw as $u) {
86 86
             $userInfo[$u["uid"]]=$u;
87 87
         }
88
-        foreach($rankList as &$r){
89
-            $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[];
88
+        foreach ($rankList as &$r) {
89
+            $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : [];
90 90
         }
91 91
         // var_dump($rankList); exit();
92 92
         return $rankList;
@@ -109,8 +109,8 @@  discard block
 block discarded – undo
109 109
                     $rankSolved=$rankItem["totValue"];
110 110
                 }
111 111
                 $rankTitle=$this->getRankTitle($rankValue);
112
-                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400);
113
-                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400);
112
+                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
113
+                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
114 114
                 $rankListCached[]=[
115 115
                     "uid"=>$rankItem["uid"],
116 116
                     "rank"=>$rankValue,
@@ -127,14 +127,14 @@  discard block
 block discarded – undo
127 127
 
128 128
     public function getProfessionalRanking()
129 129
     {
130
-        $professionalRankList = [];
131
-        $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all();
132
-        $rankIter = 0;
133
-        foreach($verifiedUsers as $user) {
134
-            $rankVal = $user['professional_rate'];
135
-            $rankTitle = self::getProfessionalTitle($rankVal);
136
-            $titleColor = self::getProfessionalColor($rankTitle);
137
-            $professionalRankList[$rankIter++] = [
130
+        $professionalRankList=[];
131
+        $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all();
132
+        $rankIter=0;
133
+        foreach ($verifiedUsers as $user) {
134
+            $rankVal=$user['professional_rate'];
135
+            $rankTitle=self::getProfessionalTitle($rankVal);
136
+            $titleColor=self::getProfessionalColor($rankTitle);
137
+            $professionalRankList[$rankIter++]=[
138 138
                 "name"=>$user["name"],
139 139
                 "uid"=>$user["uid"],
140 140
                 "avatar"=>$user["avatar"],
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
                 $tot+=$c;
157 157
             }
158 158
             foreach ($this->casualRankingPer as &$c) {
159
-                $c=round($c*$totUsers/$tot);
159
+                $c=round($c * $totUsers / $tot);
160 160
                 $cur+=$c;
161 161
                 $c=$cur;
162 162
             }
@@ -167,16 +167,16 @@  discard block
 block discarded – undo
167 167
 
168 168
     public function getRankTitle($rankVal)
169 169
     {
170
-        foreach($this->casualRankingPer as $title=>$c){
171
-            if($rankVal<=$c) return $title;
170
+        foreach ($this->casualRankingPer as $title=>$c) {
171
+            if ($rankVal<=$c) return $title;
172 172
         }
173 173
         return Arr::last($this->casualRankingPer);
174 174
     }
175 175
 
176 176
     public static function getProfessionalTitle($rankVal)
177 177
     {
178
-        foreach(self::$professionalRankingPer as $title=>$point) {
179
-            if($rankVal >= $point) return $title;
178
+        foreach (self::$professionalRankingPer as $title=>$point) {
179
+            if ($rankVal>=$point) return $title;
180 180
         }
181 181
         return Arr::last(self::$professionalRankingPer);
182 182
     }
Please login to merge, or discard this patch.
Braces   +15 added lines, -5 removed lines patch added patch discarded remove patch
@@ -65,20 +65,26 @@  discard block
 block discarded – undo
65 65
 
66 66
     public static function getColor($rankTitle)
67 67
     {
68
-        if(is_null($rankTitle)) return "";
68
+        if(is_null($rankTitle)) {
69
+            return "";
70
+        }
69 71
         return self::$casualRanking[$rankTitle];
70 72
     }
71 73
 
72 74
     public static function getProfessionalColor($rankTitle)
73 75
     {
74
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
76
+        if(is_null($rankTitle)) {
77
+            return self::$professionalRanking["None"];
78
+        }
75 79
         return self::$professionalRanking[$rankTitle];
76 80
     }
77 81
 
78 82
     public function list($num)
79 83
     {
80 84
         $rankList=Cache::tags(['rank'])->get('general');
81
-        if($rankList==null) $rankList=[];
85
+        if($rankList==null) {
86
+            $rankList=[];
87
+        }
82 88
         $rankList=array_slice($rankList,0,$num);
83 89
         $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all();
84 90
         $userInfo=[];
@@ -168,7 +174,9 @@  discard block
 block discarded – undo
168 174
     public function getRankTitle($rankVal)
169 175
     {
170 176
         foreach($this->casualRankingPer as $title=>$c){
171
-            if($rankVal<=$c) return $title;
177
+            if($rankVal<=$c) {
178
+                return $title;
179
+            }
172 180
         }
173 181
         return Arr::last($this->casualRankingPer);
174 182
     }
@@ -176,7 +184,9 @@  discard block
 block discarded – undo
176 184
     public static function getProfessionalTitle($rankVal)
177 185
     {
178 186
         foreach(self::$professionalRankingPer as $title=>$point) {
179
-            if($rankVal >= $point) return $title;
187
+            if($rankVal >= $point) {
188
+                return $title;
189
+            }
180 190
         }
181 191
         return Arr::last(self::$professionalRankingPer);
182 192
     }
Please login to merge, or discard this patch.
app/Console/Commands/Babel/SyncContest.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -14,14 +14,14 @@  discard block
 block discarded – undo
14 14
      *
15 15
      * @var string
16 16
      */
17
-    protected $signature = 'babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}';
17
+    protected $signature='babel:sync {extension : The package name of the extension} {--vcid= : The target contest of the Crawler} {--gid=1 : The holding group}';
18 18
 
19 19
     /**
20 20
      * The console command description.
21 21
      *
22 22
      * @var string
23 23
      */
24
-    protected $description = 'Crawl contests for a given Babel Extension to NOJ';
24
+    protected $description='Crawl contests for a given Babel Extension to NOJ';
25 25
 
26 26
     /**
27 27
      * Create a new command instance.
@@ -40,16 +40,16 @@  discard block
 block discarded – undo
40 40
      */
41 41
     public function handle()
42 42
     {
43
-        $extension = $this->argument('extension');
44
-        $vcid = $this->option('vcid');
45
-        $gid = $this->option('gid');
46
-        $className = "App\\Babel\\Extension\\$extension\\Synchronizer";
47
-        $all_data = [
43
+        $extension=$this->argument('extension');
44
+        $vcid=$this->option('vcid');
45
+        $gid=$this->option('gid');
46
+        $className="App\\Babel\\Extension\\$extension\\Synchronizer";
47
+        $all_data=[
48 48
             'oj'=>$extension,
49 49
             'vcid'=>$vcid,
50 50
             'gid'=>$gid,
51 51
         ];
52
-        $Sync = new $className($all_data);
52
+        $Sync=new $className($all_data);
53 53
         $Sync->crawlContest();
54 54
     }
55 55
 }
Please login to merge, or discard this patch.