Passed
Branch feature/babel (9a8402)
by John
03:52
created
app/Providers/RouteServiceProvider.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
     protected function mapWebRoutes()
53 53
     {
54 54
         Route::middleware('web')
55
-             ->namespace($this->namespace)
56
-             ->group(base_path('routes/web.php'));
55
+                ->namespace($this->namespace)
56
+                ->group(base_path('routes/web.php'));
57 57
     }
58 58
 
59 59
     /**
@@ -66,8 +66,8 @@  discard block
 block discarded – undo
66 66
     protected function mapApiRoutes()
67 67
     {
68 68
         Route::prefix('api')
69
-             ->middleware('api')
70
-             ->namespace($this->namespace)
71
-             ->group(base_path('routes/api.php'));
69
+                ->middleware('api')
70
+                ->namespace($this->namespace)
71
+                ->group(base_path('routes/api.php'));
72 72
     }
73 73
 }
Please login to merge, or discard this patch.
app/Models/ResponseModel.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
             $statusCode=200;
15 15
         }
16 16
         $output=[
17
-             'ret' => $statusCode,
17
+                'ret' => $statusCode,
18 18
             'desc' => is_null($desc) ? self::desc($statusCode) : $desc,
19 19
             'data' => $data
20 20
         ];
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
             $statusCode=1000;
28 28
         }
29 29
         $output=[
30
-             'ret' => $statusCode,
30
+                'ret' => $statusCode,
31 31
             'desc' => is_null($desc) ? self::desc($statusCode) : $desc,
32 32
             'data' => $data
33 33
         ];
@@ -44,9 +44,9 @@  discard block
 block discarded – undo
44 44
             '451'  => "Unavailable For Legal Reasons",
45 45
 
46 46
             '1000' => "Unspecified Response", /** Under normal condictions those errors shouldn't been displayed to end users
47
-                                                 *  unless they attempt to do so, some submissions should be intercepted
48
-                                                 *  by the frontend before the request sended
49
-                                                 */
47
+             *  unless they attempt to do so, some submissions should be intercepted
48
+             *  by the frontend before the request sended
49
+             */
50 50
             '1001' => "Internal Sever Error",
51 51
             '1002' => "Service Currently Unavailable",
52 52
             '1003' => "Missing Params",
Please login to merge, or discard this patch.
app/Jobs/ProcessSubmission.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
 {
15 15
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
16 16
 
17
-    public $tries = 5;
17
+    public $tries=5;
18 18
     protected $all_data=[];
19 19
 
20 20
     /**
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
 
41 41
     public function failed()
42 42
     {
43
-        $submissionModel = new SubmissionModel();
43
+        $submissionModel=new SubmissionModel();
44 44
         $submissionModel->updateSubmission($this->all_data["sid"], ["verdict"=>"Submission Error"]);
45 45
     }
46 46
 }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/SubmissionController.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -57,14 +57,14 @@
 block discarded – undo
57 57
             return ResponseModel::err(3002);
58 58
         }
59 59
         $submissionModel=new SubmissionModel();
60
-        if($all_data["method"]==1){
60
+        if ($all_data["method"]==1) {
61 61
             // NOJ Share
62 62
             $status=$submissionModel->share($all_data["sid"], Auth::check() ? Auth::user()->id : null);
63
-            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
64
-        } elseif($all_data["method"]==2){
63
+            return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status);
64
+        } elseif ($all_data["method"]==2) {
65 65
             // Pastebin
66 66
             $status=$submissionModel->sharePB($all_data["sid"], Auth::check() ? Auth::user()->id : null);
67
-            return empty($status)?ResponseModel::err(1001):ResponseModel::success(200, null, $status);
67
+            return empty($status) ?ResponseModel::err(1001) : ResponseModel::success(200, null, $status);
68 68
         } else {
69 69
             return ResponseModel::err(6002);
70 70
         }
Please login to merge, or discard this patch.
app/Http/Controllers/Ajax/ProblemController.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
         if (empty($basic)) {
112 112
             return ResponseModel::err(3001);
113 113
         }
114
-        $ret=$problemModel->addSolution($pid,Auth::user()->id,$content);
115
-        return $ret?ResponseModel::success(200):ResponseModel::err(3003);
114
+        $ret=$problemModel->addSolution($pid, Auth::user()->id, $content);
115
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3003);
116 116
     }
117 117
     /**
118 118
      * The Ajax Problem Solution Discussion Update.
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
         $problemModel=new ProblemModel();
128 128
         $psoid=$all_data["psoid"];
129 129
         $content=$all_data["content"];
130
-        $ret=$problemModel->updateSolution($psoid,Auth::user()->id,$content);
131
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
130
+        $ret=$problemModel->updateSolution($psoid, Auth::user()->id, $content);
131
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
132 132
     }
133 133
     /**
134 134
      * The Ajax Problem Solution Discussion Delete.
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
         $all_data=$request->all();
143 143
         $problemModel=new ProblemModel();
144 144
         $psoid=$all_data["psoid"];
145
-        $ret=$problemModel->removeSolution($psoid,Auth::user()->id);
146
-        return $ret?ResponseModel::success(200):ResponseModel::err(3004);
145
+        $ret=$problemModel->removeSolution($psoid, Auth::user()->id);
146
+        return $ret ?ResponseModel::success(200) : ResponseModel::err(3004);
147 147
     }
148 148
     /**
149 149
      * The Ajax Problem Solution Discussion Vote.
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
         $problemModel=new ProblemModel();
159 159
         $psoid=$all_data["psoid"];
160 160
         $type=$all_data["type"];
161
-        $ret=$problemModel->voteSolution($psoid,Auth::user()->id,$type);
162
-        return $ret["ret"]?ResponseModel::success(200,null,["votes"=>$ret["votes"],"select"=>$ret["select"]]):ResponseModel::err(3004);
161
+        $ret=$problemModel->voteSolution($psoid, Auth::user()->id, $type);
162
+        return $ret["ret"] ?ResponseModel::success(200, null, ["votes"=>$ret["votes"], "select"=>$ret["select"]]) : ResponseModel::err(3004);
163 163
     }
164 164
     /**
165 165
      * The Ajax Problem Solution Submit.
Please login to merge, or discard this patch.
app/Models/JudgerModel.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,7 @@
 block discarded – undo
61 61
     {
62 62
         $curl=curl_init();
63 63
 
64
-        if($curl===false) return [];
64
+        if ($curl===false) return [];
65 65
 
66 66
         curl_setopt_array($curl, array(
67 67
             CURLOPT_PORT => $port,
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -61,7 +61,9 @@
 block discarded – undo
61 61
     {
62 62
         $curl=curl_init();
63 63
 
64
-        if($curl===false) return [];
64
+        if($curl===false) {
65
+            return [];
66
+        }
65 67
 
66 68
         curl_setopt_array($curl, array(
67 69
             CURLOPT_PORT => $port,
Please login to merge, or discard this patch.
app/Http/Controllers/Auth/ForgotPasswordController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
      */
38 38
     public function showLinkRequestForm()
39 39
     {
40
-        return view('auth.passwords.email',[
40
+        return view('auth.passwords.email', [
41 41
             'page_title'=>"Reset Password",
42 42
             'site_title'=>"NOJ",
43 43
             'navigation' => "Account"
Please login to merge, or discard this patch.
app/Http/Controllers/Auth/ResetPasswordController.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -52,9 +52,9 @@
 block discarded – undo
52 52
      * @param  string|null  $token
53 53
      * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
54 54
      */
55
-    public function showResetForm(Request $request, $token = null)
55
+    public function showResetForm(Request $request, $token=null)
56 56
     {
57
-        return view('auth.passwords.reset',[
57
+        return view('auth.passwords.reset', [
58 58
             'token' => $token,
59 59
             'email' => $request->email,
60 60
             'page_title'=>"Reset Password",
Please login to merge, or discard this patch.
app/Models/Rating/RatingCalculator.php 2 patches
Braces   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@
 block discarded – undo
78 78
             $mid = floor(($right + $left)/2);
79 79
             if($this->getSeed($mid) < $rank){
80 80
                 $right = $mid;
81
-            }else{
81
+            } else{
82 82
                 $left = $mid;
83 83
             }
84 84
         }
Please login to merge, or discard this patch.
Spacing   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -17,24 +17,24 @@  discard block
 block discarded – undo
17 17
     public $totParticipants=0;
18 18
     public $INITIAL_RATING=1500;
19 19
 
20
-    public function __construct($cid){
20
+    public function __construct($cid) {
21 21
         $this->cid=$cid;
22 22
 
23 23
         // get rank
24 24
         $this->getRecord();
25 25
     }
26 26
 
27
-    private function getRecord(){
27
+    private function getRecord() {
28 28
         $contestRankRaw=Cache::tags(['contest', 'rank'])->get($this->cid);
29 29
 
30 30
         if ($contestRankRaw==null) {
31 31
             $contestModel=new ContestModel();
32
-            $contestRankRaw=Chache::tags('contest','rank')->get($this->cid);
32
+            $contestRankRaw=Chache::tags('contest', 'rank')->get($this->cid);
33 33
             //$contestModel->contestRankCache($this->cid);//TODO:use realtimeContestRankCache
34 34
         }
35 35
 
36
-        $this->totParticipants = count($contestRankRaw);
37
-        foreach($contestRankRaw as $c){
36
+        $this->totParticipants=count($contestRankRaw);
37
+        foreach ($contestRankRaw as $c) {
38 38
             $this->contestants[]=[
39 39
                 "uid"=>$c["uid"],
40 40
                 "points"=>$c["score"],
@@ -43,84 +43,84 @@  discard block
 block discarded – undo
43 43
         }
44 44
     }
45 45
 
46
-    private function reassignRank(){
46
+    private function reassignRank() {
47 47
         $this->sort("points");
48
-        $idx = 0;
49
-        $points = $this->contestants[0]["points"];
50
-        $i = 1;
51
-        while($i < $this->totParticipants){
52
-            if($this->contestants[$i]["points"] < $points){
53
-                $j = $idx;
54
-                while($j < $i){
55
-                    $this->contestants[$j]["rank"] = $i;
56
-                    $j += 1;
48
+        $idx=0;
49
+        $points=$this->contestants[0]["points"];
50
+        $i=1;
51
+        while ($i<$this->totParticipants) {
52
+            if ($this->contestants[$i]["points"]<$points) {
53
+                $j=$idx;
54
+                while ($j<$i) {
55
+                    $this->contestants[$j]["rank"]=$i;
56
+                    $j+=1;
57 57
                 }
58
-                $idx = $i;
59
-                $points = $this->contestants[$i]["points"];
58
+                $idx=$i;
59
+                $points=$this->contestants[$i]["points"];
60 60
             }
61
-            $i += 1;
61
+            $i+=1;
62 62
         }
63
-        $j = $idx;
64
-        while($j < $this->totParticipants){
65
-            $this->contestants[$j]["rank"] = $this->totParticipants;
66
-            $j += 1;
63
+        $j=$idx;
64
+        while ($j<$this->totParticipants) {
65
+            $this->contestants[$j]["rank"]=$this->totParticipants;
66
+            $j+=1;
67 67
         }
68 68
     }
69 69
 
70
-    private function getEloWinProbability($Ra, $Rb){
71
-        return 1.0 / (1 + pow(10, ($Rb-$Ra)/400.0));
70
+    private function getEloWinProbability($Ra, $Rb) {
71
+        return 1.0 / (1+pow(10, ($Rb-$Ra) / 400.0));
72 72
     }
73 73
 
74
-    private function getSeed($rating){
75
-        $result = 1.0;
76
-        foreach($this->contestants as $other){
77
-            $result += $this->getEloWinProbability($other["rating"], $rating);
74
+    private function getSeed($rating) {
75
+        $result=1.0;
76
+        foreach ($this->contestants as $other) {
77
+            $result+=$this->getEloWinProbability($other["rating"], $rating);
78 78
         }
79 79
         return $result;
80 80
     }
81 81
 
82
-    private function getRatingToRank($rank){
82
+    private function getRatingToRank($rank) {
83 83
         $left=1;
84 84
         $right=8000;
85
-        while($right - $left > 1){
86
-            $mid = floor(($right + $left)/2);
87
-            if($this->getSeed($mid) < $rank){
88
-                $right = $mid;
89
-            }else{
90
-                $left = $mid;
85
+        while ($right-$left>1) {
86
+            $mid=floor(($right+$left) / 2);
87
+            if ($this->getSeed($mid)<$rank) {
88
+                $right=$mid;
89
+            } else {
90
+                $left=$mid;
91 91
             }
92 92
         }
93 93
         return $left;
94 94
     }
95 95
 
96
-    private function sort($key){
97
-        usort($this->contestants, function ($a, $b) use ($key) {
96
+    private function sort($key) {
97
+        usort($this->contestants, function($a, $b) use ($key) {
98 98
             return $b[$key] <=> $a[$key];
99 99
         });
100 100
     }
101 101
 
102
-    public function calculate(){
103
-        if(empty($this->contestants)){
102
+    public function calculate() {
103
+        if (empty($this->contestants)) {
104 104
             return;
105 105
         }
106 106
 
107 107
         // recalc rank
108 108
         $this->reassignRank();
109 109
 
110
-        foreach($this->contestants as &$member){
111
-            $member["seed"] = 1.0;
112
-            foreach($this->contestants as $other){
113
-                if($member["uid"] != $other["uid"]){
114
-                    $member["seed"] += $this->getEloWinProbability($other["rating"], $member["rating"]);
110
+        foreach ($this->contestants as &$member) {
111
+            $member["seed"]=1.0;
112
+            foreach ($this->contestants as $other) {
113
+                if ($member["uid"]!=$other["uid"]) {
114
+                    $member["seed"]+=$this->getEloWinProbability($other["rating"], $member["rating"]);
115 115
                 }
116 116
             }
117 117
         }
118 118
         unset($member);
119 119
 
120
-        foreach($this->contestants as &$contestant){
121
-            $midRank = sqrt($contestant["rank"] * $contestant["seed"]);
122
-            $contestant["needRating"] = $this->getRatingToRank($midRank);
123
-            $contestant["delta"] = floor(($contestant["needRating"] - $contestant["rating"])/2);
120
+        foreach ($this->contestants as &$contestant) {
121
+            $midRank=sqrt($contestant["rank"] * $contestant["seed"]);
122
+            $contestant["needRating"]=$this->getRatingToRank($midRank);
123
+            $contestant["delta"]=floor(($contestant["needRating"]-$contestant["rating"]) / 2);
124 124
         }
125 125
         unset($contestant);
126 126
 
@@ -128,39 +128,39 @@  discard block
 block discarded – undo
128 128
 
129 129
         // DO some adjuct
130 130
         // Total sum should not be more than ZERO.
131
-        $sum = 0;
131
+        $sum=0;
132 132
 
133
-        foreach($this->contestants as $contestant){
134
-            $sum += $contestant["delta"];
133
+        foreach ($this->contestants as $contestant) {
134
+            $sum+=$contestant["delta"];
135 135
         }
136
-        $inc = -floor($sum / $this->totParticipants) - 1;
137
-        foreach($this->contestants as &$contestant){
138
-            $contestant["delta"] += $inc;
136
+        $inc=-floor($sum / $this->totParticipants)-1;
137
+        foreach ($this->contestants as &$contestant) {
138
+            $contestant["delta"]+=$inc;
139 139
         }
140 140
         unset($contestant);
141 141
 
142 142
         // Sum of top-4*sqrt should be adjusted to ZERO.
143 143
 
144
-        $sum = 0;
145
-        $zeroSumCount = min(intval(4*round(sqrt($this->totParticipants))), $this->totParticipants);
144
+        $sum=0;
145
+        $zeroSumCount=min(intval(4 * round(sqrt($this->totParticipants))), $this->totParticipants);
146 146
 
147
-        for($i=0;$i<$zeroSumCount;$i++){
148
-            $sum += $this->contestants[$i]["delta"];
147
+        for ($i=0; $i<$zeroSumCount; $i++) {
148
+            $sum+=$this->contestants[$i]["delta"];
149 149
         }
150 150
 
151
-        $inc = min(max(-floor($sum / $zeroSumCount), -10), 0);
151
+        $inc=min(max(-floor($sum / $zeroSumCount), -10), 0);
152 152
 
153
-        for($i=0;$i<$zeroSumCount;$i++){
154
-            $this->contestants[$i]["delta"] += $inc;
153
+        for ($i=0; $i<$zeroSumCount; $i++) {
154
+            $this->contestants[$i]["delta"]+=$inc;
155 155
         }
156 156
 
157 157
         return $this->validateDeltas();
158 158
     }
159 159
 
160
-    public function storage(){
160
+    public function storage() {
161 161
         $contestants=$this->contestants;
162
-        DB::transaction(function () use ($contestants) {
163
-            foreach($contestants as $contestant){
162
+        DB::transaction(function() use ($contestants) {
163
+            foreach ($contestants as $contestant) {
164 164
                 $newRating=$contestant["rating"]+$contestant["delta"];
165 165
                 DB::table("users")->where([
166 166
                     "id"=>$contestant["uid"]
@@ -182,20 +182,20 @@  discard block
 block discarded – undo
182 182
         }, 5);
183 183
     }
184 184
 
185
-    private function validateDeltas(){
185
+    private function validateDeltas() {
186 186
         $this->sort("points");
187 187
 
188
-        for($i=0;$i<$this->totParticipants;$i++){
189
-            for($j=$i+1;$j<$this->totParticipants;$j++){
190
-                if($this->contestants[$i]["rating"] > $this->contestants[$j]["rating"]){
191
-                    if($this->contestants[$i]["rating"] + $this->contestants[$i]["delta"] < $this->contestants[$j]["rating"] + $this->contestants[$j]["delta"]){
188
+        for ($i=0; $i<$this->totParticipants; $i++) {
189
+            for ($j=$i+1; $j<$this->totParticipants; $j++) {
190
+                if ($this->contestants[$i]["rating"]>$this->contestants[$j]["rating"]) {
191
+                    if ($this->contestants[$i]["rating"]+$this->contestants[$i]["delta"]<$this->contestants[$j]["rating"]+$this->contestants[$j]["delta"]) {
192 192
                         Log::warning("First rating invariant failed: {$this->contestants[i]["uid"]} vs. {$this->contestants[j]["uid"]}.");
193 193
                         return false;
194 194
                     }
195 195
                 }
196 196
 
197
-                if($this->contestants[$i]["rating"] < $this->contestants[$j]["rating"]){
198
-                    if($this->contestants[$i]["delta"] < $this->contestants[$j]["delta"]){
197
+                if ($this->contestants[$i]["rating"]<$this->contestants[$j]["rating"]) {
198
+                    if ($this->contestants[$i]["delta"]<$this->contestants[$j]["delta"]) {
199 199
                         Log::warning("Second rating invariant failed: {$this->contestants[i]["uid"]} vs.  {$this->contestants[j]["uid"]}.");
200 200
                         return false;
201 201
                     }
Please login to merge, or discard this patch.