Completed
Pull Request — master (#163)
by Corey
02:33
created
site/views/profile/index.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
   ]); ?>
25 25
           <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?>
26 26
           <?= $form->field($profile, 'send_email')->checkbox() ?>
27
-          <div id='send_email_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>>
27
+          <div id='send_email_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>>
28 28
             <?= $form->field($profile, 'partner_email1')->input('email'); ?>
29 29
             <?= $form->field($profile, 'partner_email2')->input('email'); ?>
30 30
             <?= $form->field($profile, 'partner_email3')->input('email'); ?>
Please login to merge, or discard this patch.
site/controllers/CheckinController.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     if ($form->load(Yii::$app->request->post()) && $form->validate()) {
40 40
       $form->compiled_behaviors = $form->compileBehaviors();
41 41
 
42
-      if(sizeof($form->compiled_behaviors) === 0) {
42
+      if (sizeof($form->compiled_behaviors) === 0) {
43 43
         return $this->redirect(['view']);
44 44
       }
45 45
 
@@ -49,7 +49,7 @@  discard block
 block discarded – undo
49 49
 
50 50
       return $this->redirect(['questions']);
51 51
     } else {
52
-      $behaviors  = Yii::$container->get(BehaviorInterface::class)::$behaviors;
52
+      $behaviors = Yii::$container->get(BehaviorInterface::class)::$behaviors;
53 53
       return $this->render('index', [
54 54
         'categories'    => Yii::$container->get(CategoryInterface::class)::$categories,
55 55
         'model'         => $form,
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
     $date = Yii::$container->get(TimeInterface::class)->getLocalDate();
65 65
 
66 66
     $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date);
67
-    if(count($user_behaviors) === 0) {
67
+    if (count($user_behaviors) === 0) {
68 68
       return $this->redirect(['view']);
69 69
     }
70 70
 
@@ -74,9 +74,9 @@  discard block
 block discarded – undo
74 74
       $form->deleteToday();
75 75
 
76 76
       $behaviors = $user_behavior->findAll($form->getUserBehaviorIds());
77
-      if($result = $form->saveAnswers($behaviors)) {
77
+      if ($result = $form->saveAnswers($behaviors)) {
78 78
 
79
-        if(Yii::$app->user->identity->send_email) {
79
+        if (Yii::$app->user->identity->send_email) {
80 80
           Yii::$app->user->identity->sendEmailReport($date);
81 81
           Yii::$app->session->setFlash('success', 'Your check-in is complete. A notification has been sent to your report partners.');
82 82
         } else {
@@ -129,14 +129,14 @@  discard block
 block discarded – undo
129 129
     $categories = $category::getCategories();
130 130
 
131 131
     $accum = [];
132
-    foreach($scores as $date => $cats) {
133
-      for($i = 1; $i <= 7; $i ++) {
132
+    foreach ($scores as $date => $cats) {
133
+      for ($i = 1; $i <= 7; $i++) {
134 134
         $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : [];
135 135
       }
136 136
     }
137 137
 
138 138
     $datasets = [];
139
-    foreach($accum as $idx => $data) {
139
+    foreach ($accum as $idx => $data) {
140 140
       $datasets[] = [
141 141
         'label' => $categories[$idx],
142 142
         'backgroundColor' => $category::$colors[$idx]['color'],
Please login to merge, or discard this patch.
site/tests/unit/models/EditProfileFormTest.php 2 patches
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@  discard block
 block discarded – undo
6 6
 use \site\models\EditProfileForm;
7 7
 
8 8
 class EditProfileFormTest extends \Codeception\Test\Unit {
9
-	public $values = [
10
-			'timezone' => 'America/Los_Angeles',
9
+  public $values = [
10
+      'timezone' => 'America/Los_Angeles',
11 11
       'send_email' => true,
12
-			'partner_email1' => '[email protected]',
13
-			'partner_email2' => '[email protected]',
14
-			'partner_email3' => '[email protected]',
15
-		];
12
+      'partner_email1' => '[email protected]',
13
+      'partner_email2' => '[email protected]',
14
+      'partner_email3' => '[email protected]',
15
+    ];
16 16
 
17 17
   public function testLoadUser() {
18 18
     $user = $this->getUser();
@@ -35,20 +35,20 @@  discard block
 block discarded – undo
35 35
 
36 36
     $form->attributes = $this->values;
37 37
     expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile()));
38
-		expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes));
38
+    expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes));
39 39
 
40 40
     $form->send_email = 'not_a_boolean';
41 41
     expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($form->saveProfile()));
42 42
 
43
-		$null_vals = [
44
-			'partner_email1'  => null,
45
-			'partner_email2'  => null,
46
-			'partner_email3'  => null,
43
+    $null_vals = [
44
+      'partner_email1'  => null,
45
+      'partner_email2'  => null,
46
+      'partner_email3'  => null,
47 47
       'send_email'      => null,
48
-			'timezone'        => 'America/Los_Angeles',
49
-		];
48
+      'timezone'        => 'America/Los_Angeles',
49
+    ];
50 50
     $form->send_email = false;
51
-		$ret = $form->saveProfile();
51
+    $ret = $form->saveProfile();
52 52
     expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertEquals($null_vals, $user->attributes));
53 53
 
54 54
     $form->send_email = 'not_a_boolean';
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@
 block discarded – undo
31 31
     $form->loadUser();
32 32
 
33 33
     Yii::$container
34
-      ->set(\common\interfaces\UserBehaviorInterface::class, function () { return new FakeUserBehavior(); });
34
+      ->set(\common\interfaces\UserBehaviorInterface::class, function() { return new FakeUserBehavior(); });
35 35
 
36 36
     $form->attributes = $this->values;
37 37
     expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile()));
Please login to merge, or discard this patch.
site/models/CheckinForm.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -64,10 +64,10 @@  discard block
 block discarded – undo
64 64
   }
65 65
 
66 66
   public function setBehaviors($behaviors) {
67
-    foreach($behaviors as $category_id => $category_data) {
67
+    foreach ($behaviors as $category_id => $category_data) {
68 68
       $attribute = "behaviors$category_id";
69 69
 			$this->$attribute = [];
70
-      foreach($category_data['behaviors'] as $behavior) {
70
+      foreach ($category_data['behaviors'] as $behavior) {
71 71
         $this->{$attribute}[] = $behavior['id'];
72 72
       }
73 73
     }   
@@ -75,8 +75,8 @@  discard block
 block discarded – undo
75 75
 
76 76
   public function validateBehaviors($attribute, $params) {
77 77
     if (!$this->hasErrors()) {
78
-      foreach($this->$attribute as $behavior) {
79
-        if(!is_numeric($behavior)) {
78
+      foreach ($this->$attribute as $behavior) {
79
+        if (!is_numeric($behavior)) {
80 80
           $this->addError($attribute, 'One of your behaviors is not an integer!');
81 81
         }
82 82
       }
@@ -110,17 +110,17 @@  discard block
 block discarded – undo
110 110
 
111 111
     // delete cached scores
112 112
     $time = Yii::$container->get(\common\interfaces\TimeInterface::class);
113
-    $key = "scores_of_last_month_".Yii::$app->user->id."_".$time->getLocalDate();
113
+    $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $time->getLocalDate();
114 114
     Yii::$app->cache->delete($key);
115 115
   }
116 116
 
117 117
   public function save() {
118
-    if(empty($this->compiled_behaviors)) {
118
+    if (empty($this->compiled_behaviors)) {
119 119
       $this->commpiled_behaviors = $this->compileBehaviors();
120 120
     }
121 121
 
122 122
     $rows = [];
123
-    foreach($this->compiled_behaviors as $behavior_id) {
123
+    foreach ($this->compiled_behaviors as $behavior_id) {
124 124
       $temp = [
125 125
         Yii::$app->user->id,
126 126
         (int)$behavior_id,
Please login to merge, or discard this patch.
site/models/EditProfileForm.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -69,17 +69,17 @@
 block discarded – undo
69 69
    */
70 70
   public function saveProfile() {
71 71
     if ($this->validate()) {
72
-      $user  = $this->user;
72
+      $user = $this->user;
73 73
 
74
-      if($this->timezone) {
74
+      if ($this->timezone) {
75 75
         $user->timezone = $this->timezone;
76 76
       }
77
-      if($this->send_email) {
77
+      if ($this->send_email) {
78 78
         $user->send_email = true;
79 79
       } else {
80 80
         $user->send_email = false;
81 81
       }
82
-      if($this->send_email) {
82
+      if ($this->send_email) {
83 83
         $user->partner_email1  = $this->partner_email1;
84 84
         $user->partner_email2  = $this->partner_email2;
85 85
         $user->partner_email3  = $this->partner_email3;
Please login to merge, or discard this patch.
common/models/UserBehavior.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
       ->groupBy('date, user_id')
85 85
       ->having('user_id = :user_id');
86 86
     $temp_dates = $query->all();
87
-    foreach($temp_dates as $temp_date) {
87
+    foreach ($temp_dates as $temp_date) {
88 88
       $past_checkin_dates[] = $this->time->convertUTCToLocal($temp_date['date']);
89 89
     }
90 90
 
@@ -126,9 +126,9 @@  discard block
 block discarded – undo
126 126
   }
127 127
 
128 128
   public function calculateScoresOfLastMonth() {
129
-    $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate();
129
+    $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate();
130 130
     $scores = Yii::$app->cache->get($key);
131
-    if($scores === false) {
131
+    if ($scores === false) {
132 132
       $scores = [];
133 133
 
134 134
       $dt = new DateTime("now", new DateTimeZone("UTC"));
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
       $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end);
139 139
       $local_tz = new \DateTimeZone($this->time->timezone);
140 140
       $scores = [];
141
-      foreach($periods as $period) {
141
+      foreach ($periods as $period) {
142 142
         $period->setTimezone($local_tz);
143 143
         $scores[$period->format('Y-m-d')] = $this->getBehaviorsByCategory($period);
144 144
       }
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
 
166 166
     $arr = array_reduce($behaviors, function($acc, $row) {
167 167
       $cat_id = $row['behavior']['category']['id'];
168
-      if(array_key_exists($cat_id, $acc)) {
168
+      if (array_key_exists($cat_id, $acc)) {
169 169
         $acc[$cat_id]['count'] += $row['count'];
170 170
       } else {
171 171
         $acc[$cat_id] = [
@@ -182,10 +182,10 @@  discard block
 block discarded – undo
182 182
   }
183 183
 
184 184
   public static function decorate(array $uo, $with_category = false) {
185
-    foreach($uo as &$o) {
186
-      if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) {
185
+    foreach ($uo as &$o) {
186
+      if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) {
187 187
         $o['behavior'] = $behavior;
188
-        if($with_category) {
188
+        if ($with_category) {
189 189
           $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']);
190 190
         }
191 191
       }
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
       ->having('user_id = :user_id')
207 207
       ->orderBy('count DESC');
208 208
 
209
-    if($limit instanceof \DateTime) {
209
+    if ($limit instanceof \DateTime) {
210 210
       list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d'));
211 211
       $query->params += [':start_date' => $start, ':end_date' => $end];
212 212
       $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date');
213
-    } else if(is_int($limit)) {
213
+    } else if (is_int($limit)) {
214 214
       $query->limit($limit);
215 215
     }
216 216
 
Please login to merge, or discard this patch.
common/components/Time.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,13 +36,13 @@  discard block
 block discarded – undo
36 36
    * @return \DateTime the parsed time or the default value
37 37
    */
38 38
   public function parse($time, $default = false, string $format = 'Y-m-d') {
39
-    if(is_string($time)) {
39
+    if (is_string($time)) {
40 40
       $dt = DateTime::createFromFormat($format, $time, new DateTimeZone($this->timezone));
41
-      if($dt) {
41
+      if ($dt) {
42 42
         // for some reason, using createFromFromat adds in the time. The regular DateTime constructor _does not_ do this. We manually zero out the time here to make the DateTime objects match.
43 43
         $dt->setTime(0, 0, 0);
44 44
         $formatted = $dt->format($format);
45
-        if($formatted === $time && $this->inBounds($dt)) {
45
+        if ($formatted === $time && $this->inBounds($dt)) {
46 46
           return $dt;
47 47
         }
48 48
       }
@@ -62,7 +62,7 @@  discard block
 block discarded – undo
62 62
     $test  = strtotime($dt->format('Y-m-d'));
63 63
     $now   = strtotime($this->getLocalDate());
64 64
 
65
-    if($first <= $test && $test <= $now) {
65
+    if ($first <= $test && $test <= $now) {
66 66
       return true;
67 67
     } else {
68 68
       return false;
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
   }
87 87
 
88 88
   public function getLocalTime($timezone = null) {
89
-    if($timezone === null)
89
+    if ($timezone === null)
90 90
       $timezone = $this->timezone;
91 91
 
92 92
     $timestamp = new DateTime("now", new DateTimeZone($timezone));
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
   }
95 95
 
96 96
   public function getLocalDate($timezone = null) {
97
-    if($timezone === null)
97
+    if ($timezone === null)
98 98
       $timezone = $this->timezone;
99 99
 
100 100
     return (new DateTime("now", new DateTimeZone($timezone)))
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
 
109 109
   public function getUTCBookends($local) {
110 110
     $local = trim($local);
111
-    if(strpos($local, " ")) {
111
+    if (strpos($local, " ")) {
112 112
       return false;
113 113
     }
114 114
 
@@ -130,9 +130,9 @@  discard block
 block discarded – undo
130 130
    * @return string a date string
131 131
    */
132 132
   public function validate($date) {
133
-    if(is_null($date)) {
133
+    if (is_null($date)) {
134 134
       return $this->getLocalDate();
135
-    } else if($dt = $this->parse($date)) {
135
+    } else if ($dt = $this->parse($date)) {
136 136
       return $dt->format('Y-m-d');
137 137
     } else {
138 138
       return $this->getLocalDate();
Please login to merge, or discard this patch.