Passed
Pull Request — master (#88)
by Chenyi
04:29
created
app/Models/RankModel.php 2 patches
Spacing   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
 use Illuminate\Database\Eloquent\Model;
7 7
 use Illuminate\Support\Facades\DB;
8 8
 use Illuminate\Support\Arr;
9
-use Cache,Redis;
9
+use Cache, Redis;
10 10
 
11 11
 class RankModel extends Model
12 12
 {
@@ -64,26 +64,26 @@  discard block
 block discarded – undo
64 64
 
65 65
     public static function getColor($rankTitle)
66 66
     {
67
-        if(is_null($rankTitle)) return "";
67
+        if (is_null($rankTitle)) return "";
68 68
         return self::$casualRanking[$rankTitle];
69 69
     }
70 70
 
71 71
     public static function getProfessionalColor($rankTitle)
72 72
     {
73
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
73
+        if (is_null($rankTitle)) return self::$professionalRanking["None"];
74 74
         return self::$professionalRanking[$rankTitle];
75 75
     }
76 76
 
77 77
     public function list()
78 78
     {
79 79
         $rankList=Cache::tags(['rank'])->get('general');
80
-        $userInfoRaw=DB::table("users")->select("id as uid","avatar","name")->get()->all();
80
+        $userInfoRaw=DB::table("users")->select("id as uid", "avatar", "name")->get()->all();
81 81
         $userInfo=[];
82
-        foreach($userInfoRaw as $u){
82
+        foreach ($userInfoRaw as $u) {
83 83
             $userInfo[$u["uid"]]=$u;
84 84
         }
85
-        foreach($rankList as &$r){
86
-            $r["details"]=isset($userInfo[$r["uid"]])?$userInfo[$r["uid"]]:[];
85
+        foreach ($rankList as &$r) {
86
+            $r["details"]=isset($userInfo[$r["uid"]]) ? $userInfo[$r["uid"]] : [];
87 87
         }
88 88
         // var_dump($rankList); exit();
89 89
         return $rankList;
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
                     $rankSolved=$rankItem["totValue"];
107 107
                 }
108 108
                 $rankTitle=$this->getRankTitle($rankValue);
109
-                Cache::tags(['rank',$rankItem["uid"]])->put("rank", $rankValue, 86400);
110
-                Cache::tags(['rank',$rankItem["uid"]])->put("title", $rankTitle, 86400);
109
+                Cache::tags(['rank', $rankItem["uid"]])->put("rank", $rankValue, 86400);
110
+                Cache::tags(['rank', $rankItem["uid"]])->put("title", $rankTitle, 86400);
111 111
                 $rankListCached[]=[
112 112
                     "uid"=>$rankItem["uid"],
113 113
                     "rank"=>$rankValue,
@@ -124,14 +124,14 @@  discard block
 block discarded – undo
124 124
 
125 125
     private function getProfessionalRanking()
126 126
     {
127
-        $professionalRankList = [];
128
-        $verifiedUsers = DB::table("users")->select("professional_rate","id as uid","avatar","name")->get()->all();
129
-        $rankIter = 0;
130
-        foreach($verifiedUsers as $user) {
131
-            $rankVal = $user['professional_rate'];
132
-            $rankTitle = $this->getProfessionalTitle($rankVal);
133
-            $titleColor = self::getProfessionalColor($rankTitle);
134
-            $professionalRankList[$rankIter++] = [
127
+        $professionalRankList=[];
128
+        $verifiedUsers=DB::table("users")->select("professional_rate", "id as uid", "avatar", "name")->get()->all();
129
+        $rankIter=0;
130
+        foreach ($verifiedUsers as $user) {
131
+            $rankVal=$user['professional_rate'];
132
+            $rankTitle=$this->getProfessionalTitle($rankVal);
133
+            $titleColor=self::getProfessionalColor($rankTitle);
134
+            $professionalRankList[$rankIter++]=[
135 135
                 "name"=>$user["name"],
136 136
                 "uid"=>$user["uid"],
137 137
                 "avatar"=>$user["avatar"],
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
                 $tot+=$c;
154 154
             }
155 155
             foreach ($this->casualRankingPer as &$c) {
156
-                $c=round($c*$totUsers/$tot);
156
+                $c=round($c * $totUsers / $tot);
157 157
                 $cur+=$c;
158 158
                 $c=$cur;
159 159
             }
@@ -164,16 +164,16 @@  discard block
 block discarded – undo
164 164
 
165 165
     private function getRankTitle($rankVal)
166 166
     {
167
-        foreach($this->casualRankingPer as $title=>$c){
168
-            if($rankVal<=$c) return $title;
167
+        foreach ($this->casualRankingPer as $title=>$c) {
168
+            if ($rankVal<=$c) return $title;
169 169
         }
170 170
         return Arr::last($this->casualRankingPer);
171 171
     }
172 172
 
173 173
     private function getProfessionalTitle($rankVal)
174 174
     {
175
-        foreach($this->professionalRankingPer as $title=>$point) {
176
-            if($rankVal >= $point) return $title;
175
+        foreach ($this->professionalRankingPer as $title=>$point) {
176
+            if ($rankVal>=$point) return $title;
177 177
         }
178 178
         return Arr::last($this->professionalRankingPer);
179 179
     }
Please login to merge, or discard this patch.
Braces   +12 added lines, -4 removed lines patch added patch discarded remove patch
@@ -64,13 +64,17 @@  discard block
 block discarded – undo
64 64
 
65 65
     public static function getColor($rankTitle)
66 66
     {
67
-        if(is_null($rankTitle)) return "";
67
+        if(is_null($rankTitle)) {
68
+            return "";
69
+        }
68 70
         return self::$casualRanking[$rankTitle];
69 71
     }
70 72
 
71 73
     public static function getProfessionalColor($rankTitle)
72 74
     {
73
-        if(is_null($rankTitle)) return self::$professionalRanking["None"];
75
+        if(is_null($rankTitle)) {
76
+            return self::$professionalRanking["None"];
77
+        }
74 78
         return self::$professionalRanking[$rankTitle];
75 79
     }
76 80
 
@@ -165,7 +169,9 @@  discard block
 block discarded – undo
165 169
     private function getRankTitle($rankVal)
166 170
     {
167 171
         foreach($this->casualRankingPer as $title=>$c){
168
-            if($rankVal<=$c) return $title;
172
+            if($rankVal<=$c) {
173
+                return $title;
174
+            }
169 175
         }
170 176
         return Arr::last($this->casualRankingPer);
171 177
     }
@@ -173,7 +179,9 @@  discard block
 block discarded – undo
173 179
     private function getProfessionalTitle($rankVal)
174 180
     {
175 181
         foreach($this->professionalRankingPer as $title=>$point) {
176
-            if($rankVal >= $point) return $title;
182
+            if($rankVal >= $point) {
183
+                return $title;
184
+            }
177 185
         }
178 186
         return Arr::last($this->professionalRankingPer);
179 187
     }
Please login to merge, or discard this patch.