@@ -77,10 +77,10 @@ discard block |
||
77 | 77 | $graph = Yii::$container |
78 | 78 | ->get(\common\components\Graph::class, [$this->user]); |
79 | 79 | |
80 | - if($this->timezone) { |
|
80 | + if ($this->timezone) { |
|
81 | 81 | $user->timezone = $this->timezone; |
82 | 82 | } |
83 | - if($this->expose_graph) { |
|
83 | + if ($this->expose_graph) { |
|
84 | 84 | $user->expose_graph = true; |
85 | 85 | |
86 | 86 | // generate scores graph image |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | // if they haven't done a check-in in the last month this |
92 | 92 | // will explode because $checkinss_last_month is an empty |
93 | 93 | // array |
94 | - if($checkins_last_month) { |
|
94 | + if ($checkins_last_month) { |
|
95 | 95 | $graph->create($checkins_last_month, true); |
96 | 96 | } |
97 | 97 | } else { |
@@ -99,12 +99,12 @@ discard block |
||
99 | 99 | // remove scores graph image |
100 | 100 | $graph->destroy(); |
101 | 101 | } |
102 | - if($this->send_email) { |
|
102 | + if ($this->send_email) { |
|
103 | 103 | $user->send_email = true; |
104 | 104 | } else { |
105 | 105 | $user->send_email = false; |
106 | 106 | } |
107 | - if($this->send_email) { |
|
107 | + if ($this->send_email) { |
|
108 | 108 | $user->partner_email1 = $this->partner_email1; |
109 | 109 | $user->partner_email2 = $this->partner_email2; |
110 | 110 | $user->partner_email3 = $this->partner_email3; |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | } |
54 | 54 | |
55 | 55 | /** |
56 | - * @codeCoverageIgnore |
|
57 | - */ |
|
56 | + * @codeCoverageIgnore |
|
57 | + */ |
|
58 | 58 | public function attributeLabels() { |
59 | 59 | return [ |
60 | 60 | 'partner_email1' => "Partner Email #1", |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | |
86 | 86 | // generate scores graph image |
87 | 87 | $checkins_last_month = (Yii::$container->get(\common\interfaces\UserBehaviorInterface::class)) |
88 | - ->getCheckInBreakdown(); |
|
88 | + ->getCheckInBreakdown(); |
|
89 | 89 | |
90 | 90 | // if they haven't done a check-in in the last month this |
91 | 91 | // will explode because $checkinss_last_month is an empty |
@@ -41,11 +41,11 @@ |
||
41 | 41 | |
42 | 42 | // Set up dependency injections |
43 | 43 | Yii::$container |
44 | - ->set(\common\interfaces\TimeInterface::class, function () { return new \common\components\Time('UTC'); }); |
|
44 | + ->set(\common\interfaces\TimeInterface::class, function() { return new \common\components\Time('UTC'); }); |
|
45 | 45 | Yii::$container |
46 | - ->set(\common\components\Graph::class, function () { return $this->graph; }); |
|
46 | + ->set(\common\components\Graph::class, function() { return $this->graph; }); |
|
47 | 47 | Yii::$container |
48 | - ->set(\common\interfaces\UserBehaviorInterface::class, function () { return new FakeUserBehavior(); }); |
|
48 | + ->set(\common\interfaces\UserBehaviorInterface::class, function() { return new FakeUserBehavior(); }); |
|
49 | 49 | |
50 | 50 | // Actually begin testing |
51 | 51 | $form->attributes = $this->values; |
@@ -70,11 +70,11 @@ |
||
70 | 70 | ]); ?> |
71 | 71 | <?= $form->field($profile, 'timezone')->dropDownList(array_combine($timezones, $timezones)); ?> |
72 | 72 | <?= $form->field($profile, 'expose_graph')->checkbox() ?> |
73 | - <?php if($profile->expose_graph): ?> |
|
73 | + <?php if ($profile->expose_graph): ?> |
|
74 | 74 | <div class='alert alert-success score-graph-info'>Your score graph can be found at:<br /> <a id="score-graph-link" target="_blank" href="<?=$graph_url?>"><?=$graph_url?></a></div> |
75 | 75 | <?php endif; ?> |
76 | 76 | <?= $form->field($profile, 'send_email')->checkbox() ?> |
77 | - <div id='send_email_fields' <?php if(!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
77 | + <div id='send_email_fields' <?php if (!$profile->send_email) { ?>style="display: none;"<?php } ?>> |
|
78 | 78 | <?= $form->field($profile, 'partner_email1')->input('email'); ?> |
79 | 79 | <?= $form->field($profile, 'partner_email2')->input('email'); ?> |
80 | 80 | <?= $form->field($profile, 'partner_email3')->input('email'); ?> |
@@ -64,10 +64,10 @@ discard block |
||
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 |
||
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 |
||
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, |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | )->execute(); |
140 | 140 | |
141 | 141 | // if the user has publicised their score graph, create the image |
142 | - if(Yii::$app->user->identity->expose_graph) { |
|
142 | + if (Yii::$app->user->identity->expose_graph) { |
|
143 | 143 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
144 | 144 | |
145 | - if($checkins_last_month) { |
|
145 | + if ($checkins_last_month) { |
|
146 | 146 | Yii::$container |
147 | 147 | ->get(\common\components\Graph::class, [Yii::$app->user->identity]) |
148 | 148 | ->create($checkins_last_month, true); |
@@ -39,7 +39,7 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 { |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | $raw_pie_data = $user_behavior::decorateWithCategory($user_behavior->getBehaviorsWithCounts()); |
131 | 131 | $answer_pie = $user_behavior->getBehaviorsByCategory($raw_pie_data); |
132 | 132 | |
133 | - $pie_data = [ |
|
133 | + $pie_data = [ |
|
134 | 134 | "labels" => array_column($answer_pie, "name"), |
135 | 135 | "datasets" => [[ |
136 | 136 | "data" => array_map('intval', array_column($answer_pie, "count")), |
@@ -165,14 +165,14 @@ discard block |
||
165 | 165 | $checkins = $user_behavior->getCheckInBreakdown($period); |
166 | 166 | |
167 | 167 | $accum = []; |
168 | - foreach($checkins as $date => $cats) { |
|
169 | - for($i = 1; $i <= 7; $i ++) { |
|
168 | + foreach ($checkins as $date => $cats) { |
|
169 | + for ($i = 1; $i <= 7; $i++) { |
|
170 | 170 | $accum[$i][] = array_key_exists($i, $cats) ? $cats[$i]['count'] : []; |
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
174 | 174 | $bar_datasets = []; |
175 | - foreach($accum as $idx => $data) { |
|
175 | + foreach ($accum as $idx => $data) { |
|
176 | 176 | $bar_datasets[] = [ |
177 | 177 | 'label' => ($category::getCategories())[$idx], |
178 | 178 | 'backgroundColor' => $category::$colors[$idx]['color'], |
@@ -84,7 +84,7 @@ discard block |
||
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 | |
@@ -127,12 +127,12 @@ discard block |
||
127 | 127 | |
128 | 128 | public function getCheckinBreakdown(int $period = 30) { |
129 | 129 | $datetimes = $this->time->getDateTimesInPeriod($period); |
130 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$this->time->getLocalDate(); |
|
130 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $this->time->getLocalDate(); |
|
131 | 131 | $scores = Yii::$app->cache->get($key); |
132 | 132 | |
133 | - if($scores === false) { |
|
133 | + if ($scores === false) { |
|
134 | 134 | $scores = []; |
135 | - foreach($datetimes as $datetime) { |
|
135 | + foreach ($datetimes as $datetime) { |
|
136 | 136 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
137 | 137 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
138 | 138 | } |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
159 | 159 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
160 | 160 | $cat_id = $row['behavior']['category']['id']; |
161 | - if(array_key_exists($cat_id, $acc)) { |
|
161 | + if (array_key_exists($cat_id, $acc)) { |
|
162 | 162 | $acc[$cat_id]['count'] += $row['count']; |
163 | 163 | } else { |
164 | 164 | $acc[$cat_id] = [ |
@@ -175,10 +175,10 @@ discard block |
||
175 | 175 | } |
176 | 176 | |
177 | 177 | public static function decorate(array $uo, $with_category = false) { |
178 | - foreach($uo as &$o) { |
|
179 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
178 | + foreach ($uo as &$o) { |
|
179 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
180 | 180 | $o['behavior'] = $behavior; |
181 | - if($with_category) { |
|
181 | + if ($with_category) { |
|
182 | 182 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
183 | 183 | } |
184 | 184 | } |
@@ -199,11 +199,11 @@ discard block |
||
199 | 199 | ->having('user_id = :user_id') |
200 | 200 | ->orderBy('count DESC'); |
201 | 201 | |
202 | - if($limit instanceof \DateTime) { |
|
202 | + if ($limit instanceof \DateTime) { |
|
203 | 203 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
204 | 204 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
205 | 205 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
206 | - } else if(is_int($limit)) { |
|
206 | + } else if (is_int($limit)) { |
|
207 | 207 | $query->limit($limit); |
208 | 208 | } |
209 | 209 |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function findByPasswordResetToken($token) |
145 | 145 | { |
146 | - if(!$this->isTokenCurrent($token)) { |
|
146 | + if (!$this->isTokenCurrent($token)) { |
|
147 | 147 | return null; |
148 | 148 | } |
149 | 149 | |
@@ -161,15 +161,15 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function findByVerifyEmailToken($token) |
163 | 163 | { |
164 | - if($this->isTokenConfirmed($token)) return null; |
|
164 | + if ($this->isTokenConfirmed($token)) return null; |
|
165 | 165 | |
166 | 166 | $user = $this->findOne([ |
167 | 167 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
168 | 168 | 'status' => self::STATUS_ACTIVE, |
169 | 169 | ]); |
170 | 170 | |
171 | - if($user) { |
|
172 | - if(!$this->isTokenConfirmed($token) && |
|
171 | + if ($user) { |
|
172 | + if (!$this->isTokenConfirmed($token) && |
|
173 | 173 | !$this->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
174 | 174 | return null; |
175 | 175 | } |
@@ -191,8 +191,8 @@ discard block |
||
191 | 191 | 'status' => self::STATUS_ACTIVE, |
192 | 192 | ]); |
193 | 193 | |
194 | - if($user) { |
|
195 | - if(!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
194 | + if ($user) { |
|
195 | + if (!$user->isTokenCurrent($token, 'user.verifyAccountTokenExpire')) { |
|
196 | 196 | return null; |
197 | 197 | } |
198 | 198 | } |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | public function isTokenCurrent($token, String $paramPath = 'user.passwordResetTokenExpire') { |
211 | 211 | $expire = \Yii::$app->params[$paramPath]; |
212 | 212 | $parts = explode('_', $token); |
213 | - $timestamp = (int) end($parts); |
|
213 | + $timestamp = (int)end($parts); |
|
214 | 214 | if ($timestamp + $expire < time()) { |
215 | 215 | // token expired |
216 | 216 | return false; |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param string $match the needle to search for |
226 | 226 | */ |
227 | 227 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
228 | - if(is_null($token)) $token = $this->verify_email_token; |
|
228 | + if (is_null($token)) $token = $this->verify_email_token; |
|
229 | 229 | return substr($token, -strlen($match)) === $match; |
230 | 230 | } |
231 | 231 | |
@@ -250,7 +250,7 @@ discard block |
||
250 | 250 | } |
251 | 251 | |
252 | 252 | public function isVerified() { |
253 | - if(is_null($this->verify_email_token)) { |
|
253 | + if (is_null($this->verify_email_token)) { |
|
254 | 254 | // for old users who verified their accounts before the addition of |
255 | 255 | // '_confirmed' to the token |
256 | 256 | return true; |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | } |
359 | 359 | |
360 | 360 | public function sendEmailReport($date) { |
361 | - if(!$this->send_email) return false; // no partner emails set |
|
361 | + if (!$this->send_email) return false; // no partner emails set |
|
362 | 362 | list($start, $end) = $this->time->getUTCBookends($date); |
363 | 363 | |
364 | 364 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
@@ -366,12 +366,12 @@ discard block |
||
366 | 366 | ->get(\common\components\Graph::class) |
367 | 367 | ->create($checkins_last_month); |
368 | 368 | |
369 | - $user_behaviors = $this->getUserBehaviors($date); |
|
369 | + $user_behaviors = $this->getUserBehaviors($date); |
|
370 | 370 | $user_questions = $this->getUserQuestions($date); |
371 | 371 | |
372 | 372 | $messages = []; |
373 | - foreach($this->getPartnerEmails() as $email) { |
|
374 | - if($email) { |
|
373 | + foreach ($this->getPartnerEmails() as $email) { |
|
374 | + if ($email) { |
|
375 | 375 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
376 | 376 | 'user' => $this, |
377 | 377 | 'email' => $email, |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
384 | 384 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
385 | 385 | ->setReplyTo($this->email) |
386 | - ->setSubject($this->email." has completed a Faster Scale check-in") |
|
386 | + ->setSubject($this->email . " has completed a Faster Scale check-in") |
|
387 | 387 | ->setTo($email); |
388 | 388 | } |
389 | 389 | } |
@@ -456,7 +456,7 @@ discard block |
||
456 | 456 | return \Yii::$app->mailer->compose('signupNotification') |
457 | 457 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
458 | 458 | ->setTo(\Yii::$app->params['adminEmail']) |
459 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
459 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
460 | 460 | ->send(); |
461 | 461 | } |
462 | 462 | |
@@ -464,20 +464,20 @@ discard block |
||
464 | 464 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
465 | 465 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
466 | 466 | ->setTo($this->email) |
467 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
467 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
468 | 468 | ->send(); |
469 | 469 | } |
470 | 470 | |
471 | 471 | public function sendDeleteNotificationEmail() { |
472 | 472 | $messages = []; |
473 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
474 | - if($email) { |
|
473 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
474 | + if ($email) { |
|
475 | 475 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
476 | 476 | 'user' => $this, |
477 | 477 | 'email' => $email |
478 | 478 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
479 | 479 | ->setReplyTo($this->email) |
480 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
480 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
481 | 481 | ->setTo($email); |
482 | 482 | } |
483 | 483 | } |
@@ -486,13 +486,13 @@ discard block |
||
486 | 486 | } |
487 | 487 | |
488 | 488 | public function getUserQuestions($local_date = null) { |
489 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
489 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
490 | 490 | $questions = $this->getQuestionData($local_date); |
491 | 491 | return $this->parseQuestionData($questions); |
492 | 492 | } |
493 | 493 | |
494 | 494 | public function getUserBehaviors($local_date = null) { |
495 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
495 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
496 | 496 | |
497 | 497 | $behaviors = $this->getBehaviorData($local_date); |
498 | 498 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -500,10 +500,10 @@ discard block |
||
500 | 500 | } |
501 | 501 | |
502 | 502 | public function parseQuestionData($questions) { |
503 | - if(!$questions) return []; |
|
503 | + if (!$questions) return []; |
|
504 | 504 | |
505 | 505 | $question_answers = []; |
506 | - foreach($questions as $question) { |
|
506 | + foreach ($questions as $question) { |
|
507 | 507 | $behavior = $question['behavior']; |
508 | 508 | |
509 | 509 | $question_answers[$behavior['id']]['question'] = [ |
@@ -521,10 +521,10 @@ discard block |
||
521 | 521 | } |
522 | 522 | |
523 | 523 | public function parseBehaviorData($behaviors) { |
524 | - if(!$behaviors) return []; |
|
524 | + if (!$behaviors) return []; |
|
525 | 525 | |
526 | 526 | $opts_by_cat = []; |
527 | - foreach($behaviors as $behavior) { |
|
527 | + foreach ($behaviors as $behavior) { |
|
528 | 528 | $indx = $behavior['behavior']['category_id']; |
529 | 529 | |
530 | 530 | $opts_by_cat[$indx]['category_name'] = $behavior['behavior']['category']['name']; |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | return rtrim( |
617 | 617 | strtr( |
618 | 618 | base64_encode( |
619 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
619 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
620 | 620 | ), |
621 | 621 | '+/', '-_'), |
622 | 622 | '='); |
@@ -161,7 +161,9 @@ discard block |
||
161 | 161 | */ |
162 | 162 | public function findByVerifyEmailToken($token) |
163 | 163 | { |
164 | - if($this->isTokenConfirmed($token)) return null; |
|
164 | + if($this->isTokenConfirmed($token)) { |
|
165 | + return null; |
|
166 | + } |
|
165 | 167 | |
166 | 168 | $user = $this->findOne([ |
167 | 169 | 'verify_email_token' => [$token, $token . self::CONFIRMED_STRING], |
@@ -225,7 +227,9 @@ discard block |
||
225 | 227 | * @param string $match the needle to search for |
226 | 228 | */ |
227 | 229 | public function isTokenConfirmed($token = null, String $match = self::CONFIRMED_STRING) { |
228 | - if(is_null($token)) $token = $this->verify_email_token; |
|
230 | + if(is_null($token)) { |
|
231 | + $token = $this->verify_email_token; |
|
232 | + } |
|
229 | 233 | return substr($token, -strlen($match)) === $match; |
230 | 234 | } |
231 | 235 | |
@@ -358,7 +362,10 @@ discard block |
||
358 | 362 | } |
359 | 363 | |
360 | 364 | public function sendEmailReport($date) { |
361 | - if(!$this->send_email) return false; // no partner emails set |
|
365 | + if(!$this->send_email) { |
|
366 | + return false; |
|
367 | + } |
|
368 | + // no partner emails set |
|
362 | 369 | list($start, $end) = $this->time->getUTCBookends($date); |
363 | 370 | |
364 | 371 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown(); |
@@ -486,13 +493,17 @@ discard block |
||
486 | 493 | } |
487 | 494 | |
488 | 495 | public function getUserQuestions($local_date = null) { |
489 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
496 | + if(is_null($local_date)) { |
|
497 | + $local_date = $this->time->getLocalDate(); |
|
498 | + } |
|
490 | 499 | $questions = $this->getQuestionData($local_date); |
491 | 500 | return $this->parseQuestionData($questions); |
492 | 501 | } |
493 | 502 | |
494 | 503 | public function getUserBehaviors($local_date = null) { |
495 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
504 | + if(is_null($local_date)) { |
|
505 | + $local_date = $this->time->getLocalDate(); |
|
506 | + } |
|
496 | 507 | |
497 | 508 | $behaviors = $this->getBehaviorData($local_date); |
498 | 509 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -500,7 +511,9 @@ discard block |
||
500 | 511 | } |
501 | 512 | |
502 | 513 | public function parseQuestionData($questions) { |
503 | - if(!$questions) return []; |
|
514 | + if(!$questions) { |
|
515 | + return []; |
|
516 | + } |
|
504 | 517 | |
505 | 518 | $question_answers = []; |
506 | 519 | foreach($questions as $question) { |
@@ -521,7 +534,9 @@ discard block |
||
521 | 534 | } |
522 | 535 | |
523 | 536 | public function parseBehaviorData($behaviors) { |
524 | - if(!$behaviors) return []; |
|
537 | + if(!$behaviors) { |
|
538 | + return []; |
|
539 | + } |
|
525 | 540 | |
526 | 541 | $opts_by_cat = []; |
527 | 542 | foreach($behaviors as $behavior) { |
@@ -337,7 +337,7 @@ |
||
337 | 337 | ], [ |
338 | 338 | ], [ |
339 | 339 | ], [ |
340 | - ], [ [ |
|
340 | + ], [[ |
|
341 | 341 | 'user_id' => 1, |
342 | 342 | 'behavior_id' => 117, |
343 | 343 | 'count' => 1, |
@@ -105,19 +105,19 @@ discard block |
||
105 | 105 | expect('decorate should add Behavior data and Category data to an array of UserBehaviors', |
106 | 106 | $this->assertEquals( |
107 | 107 | $this->user_behavior->decorateWithCategory($this->singleSimpleBehaviorNoBehavior), |
108 | - [['id' => 396, |
|
109 | - 'user_id' => 2, |
|
110 | - 'behavior_id' => 107, |
|
111 | - 'date' => '2016-06-17 04:12:43', |
|
112 | - 'behavior' => [ |
|
113 | - 'id' => 107, |
|
114 | - 'name' => 'numb', |
|
115 | - 'category_id' => 6, |
|
116 | - 'category' => [ |
|
117 | - 'id' => 6, |
|
118 | - 'name' => 'Exhausted', |
|
119 | - ] |
|
120 | - ]]])); |
|
108 | + [['id' => 396, |
|
109 | + 'user_id' => 2, |
|
110 | + 'behavior_id' => 107, |
|
111 | + 'date' => '2016-06-17 04:12:43', |
|
112 | + 'behavior' => [ |
|
113 | + 'id' => 107, |
|
114 | + 'name' => 'numb', |
|
115 | + 'category_id' => 6, |
|
116 | + 'category' => [ |
|
117 | + 'id' => 6, |
|
118 | + 'name' => 'Exhausted', |
|
119 | + ] |
|
120 | + ]]])); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | public function testGetBehaviorsByCategory() { |
@@ -198,6 +198,6 @@ discard block |
||
198 | 198 | $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
199 | 199 | $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
200 | 200 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
201 | - expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
201 | + expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
|
202 | 202 | } |
203 | 203 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | ]; |
34 | 34 | public function setUp() { |
35 | 35 | // pull in test data |
36 | - $data = require(__DIR__.'/../data/checkinData.php'); |
|
36 | + $data = require(__DIR__ . '/../data/checkinData.php'); |
|
37 | 37 | $this->singleBhvr = $data['singleBhvr']; |
38 | 38 | $this->manyBhvrs = $data['manyBhvrs']; |
39 | 39 | $this->allBhvrs = $data['allBhvrs']; |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | $this->container->set('common\interfaces\UserInterface', '\site\tests\_support\MockUser'); |
44 | 44 | $this->container->set('common\interfaces\QuestionInterface', '\site\tests\_support\MockQuestion'); |
45 | 45 | $this->container->set('common\interfaces\BehaviorInterface', 'common\models\Behavior'); |
46 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
46 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
47 | 47 | return new \common\components\Time('America/Los_Angeles'); |
48 | 48 | }); |
49 | 49 | |
@@ -195,8 +195,8 @@ discard block |
||
195 | 195 | ->setMethods(['getIsNewRecord', 'save', 'getBehaviorsByDate', 'getBehaviorsWithCounts']) |
196 | 196 | ->getMock(); |
197 | 197 | |
198 | - $bhvrs = require(__DIR__.'/../data/behaviorsWithCounts.php'); |
|
199 | - $expected = require(__DIR__.'/../data/expected_getCheckinBreakdown.php'); |
|
198 | + $bhvrs = require(__DIR__ . '/../data/behaviorsWithCounts.php'); |
|
199 | + $expected = require(__DIR__ . '/../data/expected_getCheckinBreakdown.php'); |
|
200 | 200 | $this->user_behavior->method('getBehaviorsWithCounts')->willReturn(...$bhvrs); |
201 | 201 | expect('asdf', $this->assertEquals($expected, $this->user_behavior->getCheckinBreakdown())); |
202 | 202 | } |