Completed
Push — master ( 818991...ace19a )
by Corey
03:14
created
common/models/UserBehavior.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
       ->groupBy('date, user_id')
92 92
       ->having('user_id = :user_id');
93 93
     $temp_dates = $query->all();
94
-    foreach($temp_dates as $temp_date) {
94
+    foreach ($temp_dates as $temp_date) {
95 95
       $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']);
96 96
     }
97 97
 
@@ -126,12 +126,12 @@  discard block
 block discarded – undo
126 126
 
127 127
   public function getCheckinBreakdown(int $period = 30) {
128 128
     $datetimes = $this->time->getDateTimesInPeriod($period);
129
-    $key = "checkins_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate();
129
+    $key = "checkins_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate();
130 130
     $checkins = Yii::$app->cache->get($key);
131 131
 
132
-    if($checkins === false) {
132
+    if ($checkins === false) {
133 133
       $checkins = [];
134
-      foreach($datetimes as $datetime) {
134
+      foreach ($datetimes as $datetime) {
135 135
         $behaviors = self::decorate($this->getBehaviorsWithCounts($datetime));
136 136
         $checkins[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors);
137 137
       }
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
   public function getBehaviorsByCategory(array $decorated_behaviors) {
158 158
     $arr = array_reduce($decorated_behaviors, function($acc, $row) {
159 159
       $cat_id = $row['category_id'];
160
-      if(array_key_exists($cat_id, $acc)) {
160
+      if (array_key_exists($cat_id, $acc)) {
161 161
         $acc[$cat_id]['count'] += $row['count'];
162 162
       } else {
163 163
         $acc[$cat_id] = [
@@ -189,11 +189,11 @@  discard block
 block discarded – undo
189 189
       ->having('user_id = :user_id')
190 190
       ->orderBy('count DESC');
191 191
 
192
-    if($limit instanceof \DateTime) {
192
+    if ($limit instanceof \DateTime) {
193 193
       list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d'));
194 194
       $query->params += [':start_date' => $start, ':end_date' => $end];
195 195
       $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date');
196
-    } else if(is_int($limit)) {
196
+    } else if (is_int($limit)) {
197 197
       $query->limit($limit);
198 198
     }
199 199
     return $query->all();
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
    * @return array
212 212
    */
213 213
   public function getByDate(int $user_id, $local_date = null) {
214
-    if(is_null($local_date)) $local_date = $this->time->getLocalDate();
214
+    if (is_null($local_date)) $local_date = $this->time->getLocalDate();
215 215
 
216 216
     $behaviors = $this->getBehaviorData($user_id, $local_date);
217 217
     $behaviors = self::decorate($behaviors);
@@ -224,10 +224,10 @@  discard block
 block discarded – undo
224 224
    * @return an array of decorated UserBehaviors, each with an added Category and Behavior
225 225
    */
226 226
   public static function decorate(array $uo) {
227
-    foreach($uo as &$o) {
227
+    foreach ($uo as &$o) {
228 228
       $behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id']);
229 229
       $category = \common\models\Category::getCategory('id', $o['category_id']);
230
-      if($behavior) {
230
+      if ($behavior) {
231 231
         $o['behavior'] = $behavior;
232 232
       } else if (array_key_exists('custom_behavior', $o)) {
233 233
         // if a behavior isn't set, this may be a custom_behavior
@@ -236,7 +236,7 @@  discard block
 block discarded – undo
236 236
           'name' => $o['custom_behavior'],
237 237
         ];
238 238
       } // else -- something is weird
239
-      if($category) {
239
+      if ($category) {
240 240
         $o['category'] = $category;
241 241
       }
242 242
     }
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
 
263 263
   // TODO: this should probably be a private method...but unit testing is hard
264 264
   public function parseBehaviorData($behaviors) {
265
-    if(!$behaviors) return [];
265
+    if (!$behaviors) return [];
266 266
 
267 267
     $bhvrs_by_cat = [];
268
-    foreach($behaviors as $behavior) {
268
+    foreach ($behaviors as $behavior) {
269 269
       $indx = $behavior['category_id'];
270 270
 
271 271
       $bname = AH::getValue($behavior, 'behavior.name', AH::getValue($behavior, 'custom_behavior'));
Please login to merge, or discard this patch.