Passed
Push — master ( 41f848...de078e )
by Corey
05:23 queued 02:26
created
migrations/m190829_141748_alter_user_behavior_link_add_category_id.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -22,20 +22,20 @@
 block discarded – undo
22 22
 
23 23
       // then populate the columns
24 24
       $query = (new Query())->from('user_behavior_link');
25
-      foreach($query->batch() as $rows) {
26
-        foreach($rows as $row) {
25
+      foreach ($query->batch() as $rows) {
26
+        foreach ($rows as $row) {
27 27
           $bhvr = Behavior::getBehavior('id', $row['behavior_id']);
28
-          if($bhvr) {
28
+          if ($bhvr) {
29 29
             $this->update('{{%user_behavior_link}}', ['category_id' => $bhvr['category_id']], ['id' => $row['id']]);
30 30
           }
31 31
         }
32 32
       }
33 33
 
34 34
       $query = (new Query())->from('question');
35
-      foreach($query->batch() as $rows) {
36
-        foreach($rows as $row) {
35
+      foreach ($query->batch() as $rows) {
36
+        foreach ($rows as $row) {
37 37
           $bhvr = Behavior::getBehavior('id', $row['behavior_id']);
38
-          if($bhvr) {
38
+          if ($bhvr) {
39 39
             $this->update('{{%question}}', ['category_id' => $bhvr['category_id']], ['id' => $row['id']]);
40 40
           }
41 41
         }
Please login to merge, or discard this patch.
site/tests/unit/models/CheckinFormTest.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -95,8 +95,8 @@  discard block
 block discarded – undo
95 95
       parent::setUp();
96 96
     }
97 97
 
98
-		public function testAttributeLabels()
99
-		{
98
+    public function testAttributeLabels()
99
+    {
100 100
         $this->specify('attributeLabels should function properly', function () {
101 101
           $model = $this->container->get('\site\models\CheckinForm');
102 102
           expect('attributeLabels should be correct', $this->assertEquals([
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
         $this->specify('setBehaviors should function properly', function () {
117 117
           $model = $this->container->get('\site\models\CheckinForm');
118 118
 
119
-					$model->setBehaviors($this->behaviors);
119
+          $model->setBehaviors($this->behaviors);
120 120
           expect('behaviors1 should be correct', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
121 121
           expect('behaviors2 should be correct', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
122 122
           expect('behaviors3 should be correct', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
           expect('behaviors6 should be correct', $this->assertEquals([ 0 => 104 ], $model->behaviors6));
126 126
           expect('behaviors7 should be correct', $this->assertEquals([ 0 => 128 ], $model->behaviors7));
127 127
 
128
-					$model->setBehaviors($this->behaviors);
128
+          $model->setBehaviors($this->behaviors);
129 129
           expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
130 130
           expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
131 131
           expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
@@ -136,19 +136,19 @@  discard block
 block discarded – undo
136 136
         });
137 137
     }
138 138
 
139
-		public function testValidateBehaviors()
140
-		{
139
+    public function testValidateBehaviors()
140
+    {
141 141
         $this->specify('validateBehaviors should function properly', function () {
142 142
           $model = $this->container->get('\site\models\CheckinForm');
143
-					$model->setBehaviors($this->behaviors);
143
+          $model->setBehaviors($this->behaviors);
144 144
           expect('validation should be good', $this->assertTrue($model->validate()));
145 145
 
146 146
           $model->behaviors1[0] = 'bad';
147 147
           expect('validation should be bad', $this->assertFalse($model->validate()));
148 148
         });
149
-		}
149
+    }
150 150
 
151
-		public function testCompileBehaviors()
151
+    public function testCompileBehaviors()
152 152
     {
153 153
       $model = $this->container->get('\site\models\CheckinForm');
154 154
       $model->setBehaviors($this->behaviors);
@@ -211,6 +211,6 @@  discard block
 block discarded – undo
211 211
       $expected_behaviors = $base_behaviors;
212 212
       $expected_behaviors[7] += $other_behaviors;
213 213
 
214
-       expect('mergeWithDefault should return the given behaviors merged in with the base behaviors', $this->assertEquals($base_behaviors, $model->mergeWithDefault($other_behaviors)));
214
+        expect('mergeWithDefault should return the given behaviors merged in with the base behaviors', $this->assertEquals($base_behaviors, $model->mergeWithDefault($other_behaviors)));
215 215
     }
216 216
 }
Please login to merge, or discard this patch.
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -89,7 +89,7 @@  discard block
 block discarded – undo
89 89
     protected function setUp() {
90 90
       $this->container = new \yii\di\Container;
91 91
       $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior');
92
-    $this->container->set('common\interfaces\TimeInterface', function () {
92
+    $this->container->set('common\interfaces\TimeInterface', function() {
93 93
       return new \common\components\Time('America/Los_Angeles');
94 94
     });
95 95
       parent::setUp();
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 
98 98
 		public function testAttributeLabels()
99 99
 		{
100
-        $this->specify('attributeLabels should function properly', function () {
100
+        $this->specify('attributeLabels should function properly', function() {
101 101
           $model = $this->container->get('\site\models\CheckinForm');
102 102
           expect('attributeLabels should be correct', $this->assertEquals([
103 103
             'behaviors1' => 'Restoration',
@@ -113,32 +113,32 @@  discard block
 block discarded – undo
113 113
 
114 114
     public function testSetBehaviors()
115 115
     {
116
-        $this->specify('setBehaviors should function properly', function () {
116
+        $this->specify('setBehaviors should function properly', function() {
117 117
           $model = $this->container->get('\site\models\CheckinForm');
118 118
 
119 119
 					$model->setBehaviors($this->behaviors);
120
-          expect('behaviors1 should be correct', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
121
-          expect('behaviors2 should be correct', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
122
-          expect('behaviors3 should be correct', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
123
-          expect('behaviors4 should be correct', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4));
124
-          expect('behaviors5 should be correct', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5));
125
-          expect('behaviors6 should be correct', $this->assertEquals([ 0 => 104 ], $model->behaviors6));
126
-          expect('behaviors7 should be correct', $this->assertEquals([ 0 => 128 ], $model->behaviors7));
120
+          expect('behaviors1 should be correct', $this->assertEquals([0 => 7], $model->behaviors1));
121
+          expect('behaviors2 should be correct', $this->assertEquals([0 => 12, 1 => 13, 2 => 17, 3 => 18], $model->behaviors2));
122
+          expect('behaviors3 should be correct', $this->assertEquals([0 => 28, 1 => 38, 2 => 46], $model->behaviors3));
123
+          expect('behaviors4 should be correct', $this->assertEquals([0 => 47, 1 => 56, 2 => 62], $model->behaviors4));
124
+          expect('behaviors5 should be correct', $this->assertEquals([0 => 78, 1 => 79], $model->behaviors5));
125
+          expect('behaviors6 should be correct', $this->assertEquals([0 => 104], $model->behaviors6));
126
+          expect('behaviors7 should be correct', $this->assertEquals([0 => 128], $model->behaviors7));
127 127
 
128 128
 					$model->setBehaviors($this->behaviors);
129
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 7 ], $model->behaviors1));
130
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 12, 1 => 13, 2 => 17, 3 => 18 ], $model->behaviors2));
131
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 28, 1 => 38, 2 => 46 ], $model->behaviors3));
132
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 47, 1 => 56, 2 => 62 ], $model->behaviors4));
133
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 78, 1 => 79 ], $model->behaviors5));
134
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 104 ], $model->behaviors6));
135
-          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([ 0 => 128 ], $model->behaviors7));
129
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 7], $model->behaviors1));
130
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 12, 1 => 13, 2 => 17, 3 => 18], $model->behaviors2));
131
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 28, 1 => 38, 2 => 46], $model->behaviors3));
132
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 47, 1 => 56, 2 => 62], $model->behaviors4));
133
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 78, 1 => 79], $model->behaviors5));
134
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 104], $model->behaviors6));
135
+          expect('setBehaviors should not append behaviors to existing ones', $this->assertEquals([0 => 128], $model->behaviors7));
136 136
         });
137 137
     }
138 138
 
139 139
 		public function testValidateBehaviors()
140 140
 		{
141
-        $this->specify('validateBehaviors should function properly', function () {
141
+        $this->specify('validateBehaviors should function properly', function() {
142 142
           $model = $this->container->get('\site\models\CheckinForm');
143 143
 					$model->setBehaviors($this->behaviors);
144 144
           expect('validation should be good', $this->assertTrue($model->validate()));
Please login to merge, or discard this patch.
common/mail/checkinReport.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -125,14 +125,14 @@  discard block
 block discarded – undo
125 125
                                                 <th style="Margin:0;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
126 126
 
127 127
 <?php
128
-if($questions) {
129
-  foreach($questions as $behavior_id => $behavior_questions) {
128
+if ($questions) {
129
+  foreach ($questions as $behavior_id => $behavior_questions) {
130 130
 ?>
131 131
 
132 132
                                                    <h4 style="Margin:0;Margin-bottom:10px;color:#37b98f;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:24px;font-weight:400;line-height:1.3;margin:0;margin-bottom:5px;padding:0 8px;text-align:left;word-wrap:normal"> <?= $behavior_questions['question']['title'] ?> </h4>
133 133
 
134 134
 <?php
135
-    foreach($behavior_questions['answers'] as $key => $question) {  ?>
135
+    foreach ($behavior_questions['answers'] as $key => $question) {  ?>
136 136
       <p style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0 8px 4px 8px;text-align:left"><strong><?=$question['title']?></strong> <?=$question['answer']?></p>
137 137
 <?php
138 138
     }
@@ -189,12 +189,12 @@  discard block
 block discarded – undo
189 189
                                                 <th style="Margin:0;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;padding:0;text-align:left">
190 190
 
191 191
 <?php
192
-if($user_behaviors) {
193
-  foreach($user_behaviors as $cat_key => $behaviors) { ?>
192
+if ($user_behaviors) {
193
+  foreach ($user_behaviors as $cat_key => $behaviors) { ?>
194 194
         <p style="Margin:0;Margin-bottom:10px;color:#0a0a0a;font-family:Arial,Verdana,Helvetica,sans-serif;font-size:16px;font-weight:400;line-height:1.3;margin:0;margin-bottom:10px;padding:0 8px 4px 8px;text-align:left">
195 195
           <strong style="color:#37b98f"><?=  $categories[$cat_key] ?></strong>
196 196
 <?php
197
-    foreach($behaviors as $behavior) { ?>
197
+    foreach ($behaviors as $behavior) { ?>
198 198
         <br><?= $behavior['name'] ?>
199 199
 <?php
200 200
     }
Please login to merge, or discard this patch.
common/models/UserBehavior.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
       ->groupBy('date, user_id')
87 87
       ->having('user_id = :user_id');
88 88
     $temp_dates = $query->all();
89
-    foreach($temp_dates as $temp_date) {
89
+    foreach ($temp_dates as $temp_date) {
90 90
       $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']);
91 91
     }
92 92
 
@@ -115,12 +115,12 @@  discard block
 block discarded – undo
115 115
 
116 116
   public function getCheckinBreakdown(int $period = 30) {
117 117
     $datetimes = $this->time->getDateTimesInPeriod($period);
118
-    $key = "checkins_".Yii::$app->user->id."_{$period}_".$this->time->getLocalDate();
118
+    $key = "checkins_" . Yii::$app->user->id . "_{$period}_" . $this->time->getLocalDate();
119 119
     $checkins = Yii::$app->cache->get($key);
120 120
 
121
-    if($checkins === false) {
121
+    if ($checkins === false) {
122 122
       $checkins = [];
123
-      foreach($datetimes as $datetime) {
123
+      foreach ($datetimes as $datetime) {
124 124
         $behaviors = self::decorate($this->getBehaviorsWithCounts($datetime));
125 125
         $checkins[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors);
126 126
       }
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
   public function getBehaviorsByCategory(array $decorated_behaviors) {
147 147
     $arr = array_reduce($decorated_behaviors, function($acc, $row) {
148 148
       $cat_id = $row['category_id'];
149
-      if(array_key_exists($cat_id, $acc)) {
149
+      if (array_key_exists($cat_id, $acc)) {
150 150
         $acc[$cat_id]['count'] += $row['count'];
151 151
       } else {
152 152
         $acc[$cat_id] = [
@@ -178,11 +178,11 @@  discard block
 block discarded – undo
178 178
       ->having('user_id = :user_id')
179 179
       ->orderBy('count DESC');
180 180
 
181
-    if($limit instanceof \DateTime) {
181
+    if ($limit instanceof \DateTime) {
182 182
       list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d'));
183 183
       $query->params += [':start_date' => $start, ':end_date' => $end];
184 184
       $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date');
185
-    } else if(is_int($limit)) {
185
+    } else if (is_int($limit)) {
186 186
       $query->limit($limit);
187 187
     }
188 188
     return $query->all();
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
    * @return array
197 197
    */
198 198
   public function getByDate(int $user_id, $local_date = null) {
199
-    if(is_null($local_date)) $local_date = $this->time->getLocalDate();
199
+    if (is_null($local_date)) $local_date = $this->time->getLocalDate();
200 200
 
201 201
     $behaviors = $this->getBehaviorData($user_id, $local_date);
202 202
     $behaviors = self::decorate($behaviors);
@@ -209,12 +209,12 @@  discard block
 block discarded – undo
209 209
    * @return an array of decorated UserBehaviors, each with an added Category and Behavior
210 210
    */
211 211
   public static function decorate(array $uo) {
212
-    foreach($uo as &$o) {
212
+    foreach ($uo as &$o) {
213 213
       $behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id']);
214 214
       $category = \common\models\Category::getCategory('id', $o['category_id']);
215 215
       // if this behavior does not have a valid behavior or category, something
216 216
       // is weird and we don't want to do this halfway.
217
-      if($behavior && $category) {
217
+      if ($behavior && $category) {
218 218
         $o['behavior'] = $behavior;
219 219
         $o['category'] = $category;
220 220
       }
@@ -241,10 +241,10 @@  discard block
 block discarded – undo
241 241
 
242 242
   // TODO: this should probably be a private method...but unit testing is hard
243 243
   public function parseBehaviorData($behaviors) {
244
-    if(!$behaviors) return [];
244
+    if (!$behaviors) return [];
245 245
 
246 246
     $bhvrs_by_cat = [];
247
-    foreach($behaviors as $behavior) {
247
+    foreach ($behaviors as $behavior) {
248 248
       $indx = $behavior['category_id'];
249 249
 
250 250
       $bhvrs_by_cat[$indx][$behavior['behavior']['name']] = [
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -196,7 +196,9 @@  discard block
 block discarded – undo
196 196
    * @return array
197 197
    */
198 198
   public function getByDate(int $user_id, $local_date = null) {
199
-    if(is_null($local_date)) $local_date = $this->time->getLocalDate();
199
+    if(is_null($local_date)) {
200
+      $local_date = $this->time->getLocalDate();
201
+    }
200 202
 
201 203
     $behaviors = $this->getBehaviorData($user_id, $local_date);
202 204
     $behaviors = self::decorate($behaviors);
@@ -241,7 +243,9 @@  discard block
 block discarded – undo
241 243
 
242 244
   // TODO: this should probably be a private method...but unit testing is hard
243 245
   public function parseBehaviorData($behaviors) {
244
-    if(!$behaviors) return [];
246
+    if(!$behaviors) {
247
+      return [];
248
+    }
245 249
 
246 250
     $bhvrs_by_cat = [];
247 251
     foreach($behaviors as $behavior) {
Please login to merge, or discard this patch.