@@ -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->isPartnerEnabled()) return false; // no partner emails set |
|
365 | + if(!$this->isPartnerEnabled()) { |
|
366 | + return false; |
|
367 | + } |
|
368 | + // no partner emails set |
|
362 | 369 | |
363 | 370 | list($start, $end) = $this->time->getUTCBookends($date); |
364 | 371 | |
@@ -489,13 +496,17 @@ discard block |
||
489 | 496 | } |
490 | 497 | |
491 | 498 | public function getUserQuestions($local_date = null) { |
492 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
499 | + if(is_null($local_date)) { |
|
500 | + $local_date = $this->time->getLocalDate(); |
|
501 | + } |
|
493 | 502 | $questions = $this->getQuestionData($local_date); |
494 | 503 | return $this->parseQuestionData($questions); |
495 | 504 | } |
496 | 505 | |
497 | 506 | public function getUserBehaviors($local_date = null) { |
498 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
507 | + if(is_null($local_date)) { |
|
508 | + $local_date = $this->time->getLocalDate(); |
|
509 | + } |
|
499 | 510 | |
500 | 511 | $behaviors = $this->getBehaviorData($local_date); |
501 | 512 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -503,7 +514,9 @@ discard block |
||
503 | 514 | } |
504 | 515 | |
505 | 516 | public function parseQuestionData($questions) { |
506 | - if(!$questions) return []; |
|
517 | + if(!$questions) { |
|
518 | + return []; |
|
519 | + } |
|
507 | 520 | |
508 | 521 | $question_answers = []; |
509 | 522 | foreach($questions as $question) { |
@@ -524,7 +537,9 @@ discard block |
||
524 | 537 | } |
525 | 538 | |
526 | 539 | public function parseBehaviorData($behaviors) { |
527 | - if(!$behaviors) return []; |
|
540 | + if(!$behaviors) { |
|
541 | + return []; |
|
542 | + } |
|
528 | 543 | |
529 | 544 | $opts_by_cat = []; |
530 | 545 | foreach($behaviors as $behavior) { |
@@ -587,7 +602,9 @@ discard block |
||
587 | 602 | } |
588 | 603 | |
589 | 604 | public function isOverThreshold($score) { |
590 | - if(!$this->isPartnerEnabled()) return false; |
|
605 | + if(!$this->isPartnerEnabled()) { |
|
606 | + return false; |
|
607 | + } |
|
591 | 608 | |
592 | 609 | $threshold = $this->email_threshold; |
593 | 610 |
@@ -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->isPartnerEnabled()) return false; // no partner emails set |
|
361 | + if (!$this->isPartnerEnabled()) return false; // no partner emails set |
|
362 | 362 | |
363 | 363 | list($start, $end) = $this->time->getUTCBookends($date); |
364 | 364 | |
@@ -368,12 +368,12 @@ discard block |
||
368 | 368 | ->create($scores_of_month); |
369 | 369 | |
370 | 370 | $score = $this->user_behavior->calculateScoreByUTCRange($start, $end); |
371 | - $user_behaviors = $this->getUserBehaviors($date); |
|
371 | + $user_behaviors = $this->getUserBehaviors($date); |
|
372 | 372 | $user_questions = $this->getUserQuestions($date); |
373 | 373 | |
374 | 374 | $messages = []; |
375 | - foreach($this->getPartnerEmails() as $email) { |
|
376 | - if($email) { |
|
375 | + foreach ($this->getPartnerEmails() as $email) { |
|
376 | + if ($email) { |
|
377 | 377 | $messages[] = Yii::$app->mailer->compose('checkinReport', [ |
378 | 378 | 'user' => $this, |
379 | 379 | 'email' => $email, |
@@ -386,7 +386,7 @@ discard block |
||
386 | 386 | 'behaviors_list' => \common\models\Behavior::$behaviors, |
387 | 387 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
388 | 388 | ->setReplyTo($this->email) |
389 | - ->setSubject($this->email." has scored high in The Faster Scale App") |
|
389 | + ->setSubject($this->email . " has scored high in The Faster Scale App") |
|
390 | 390 | ->setTo($email); |
391 | 391 | } |
392 | 392 | } |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | return \Yii::$app->mailer->compose('signupNotification') |
460 | 460 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
461 | 461 | ->setTo(\Yii::$app->params['adminEmail']) |
462 | - ->setSubject('A new user has signed up for '.\Yii::$app->name) |
|
462 | + ->setSubject('A new user has signed up for ' . \Yii::$app->name) |
|
463 | 463 | ->send(); |
464 | 464 | } |
465 | 465 | |
@@ -467,20 +467,20 @@ discard block |
||
467 | 467 | return \Yii::$app->mailer->compose('verifyEmail', ['user' => $this]) |
468 | 468 | ->setFrom([\Yii::$app->params['supportEmail'] => \Yii::$app->name]) |
469 | 469 | ->setTo($this->email) |
470 | - ->setSubject('Please verify your '.\Yii::$app->name .' account') |
|
470 | + ->setSubject('Please verify your ' . \Yii::$app->name . ' account') |
|
471 | 471 | ->send(); |
472 | 472 | } |
473 | 473 | |
474 | 474 | public function sendDeleteNotificationEmail() { |
475 | 475 | $messages = []; |
476 | - foreach(array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
477 | - if($email) { |
|
476 | + foreach (array_merge([$this->email], $this->getPartnerEmails()) as $email) { |
|
477 | + if ($email) { |
|
478 | 478 | $messages[] = Yii::$app->mailer->compose('deleteNotification', [ |
479 | 479 | 'user' => $this, |
480 | 480 | 'email' => $email |
481 | 481 | ])->setFrom([Yii::$app->params['supportEmail'] => Yii::$app->name]) |
482 | 482 | ->setReplyTo($this->email) |
483 | - ->setSubject($this->email." has deleted their The Faster Scale App account") |
|
483 | + ->setSubject($this->email . " has deleted their The Faster Scale App account") |
|
484 | 484 | ->setTo($email); |
485 | 485 | } |
486 | 486 | } |
@@ -489,13 +489,13 @@ discard block |
||
489 | 489 | } |
490 | 490 | |
491 | 491 | public function getUserQuestions($local_date = null) { |
492 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
492 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
493 | 493 | $questions = $this->getQuestionData($local_date); |
494 | 494 | return $this->parseQuestionData($questions); |
495 | 495 | } |
496 | 496 | |
497 | 497 | public function getUserBehaviors($local_date = null) { |
498 | - if(is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
498 | + if (is_null($local_date)) $local_date = $this->time->getLocalDate(); |
|
499 | 499 | |
500 | 500 | $behaviors = $this->getBehaviorData($local_date); |
501 | 501 | $behaviors = $this->user_behavior::decorateWithCategory($behaviors); |
@@ -503,10 +503,10 @@ discard block |
||
503 | 503 | } |
504 | 504 | |
505 | 505 | public function parseQuestionData($questions) { |
506 | - if(!$questions) return []; |
|
506 | + if (!$questions) return []; |
|
507 | 507 | |
508 | 508 | $question_answers = []; |
509 | - foreach($questions as $question) { |
|
509 | + foreach ($questions as $question) { |
|
510 | 510 | $behavior = $question['behavior']; |
511 | 511 | |
512 | 512 | $question_answers[$behavior['id']]['question'] = [ |
@@ -524,10 +524,10 @@ discard block |
||
524 | 524 | } |
525 | 525 | |
526 | 526 | public function parseBehaviorData($behaviors) { |
527 | - if(!$behaviors) return []; |
|
527 | + if (!$behaviors) return []; |
|
528 | 528 | |
529 | 529 | $opts_by_cat = []; |
530 | - foreach($behaviors as $behavior) { |
|
530 | + foreach ($behaviors as $behavior) { |
|
531 | 531 | $indx = $behavior['behavior']['category_id']; |
532 | 532 | |
533 | 533 | $opts_by_cat[$indx]['category_name'] = $behavior['behavior']['category']['name']; |
@@ -576,7 +576,7 @@ discard block |
||
576 | 576 | } |
577 | 577 | |
578 | 578 | public function isPartnerEnabled() { |
579 | - if((is_integer($this->email_threshold) |
|
579 | + if ((is_integer($this->email_threshold) |
|
580 | 580 | && $this->email_threshold >= 0) |
581 | 581 | && ($this->partner_email1 |
582 | 582 | || $this->partner_email2 |
@@ -587,7 +587,7 @@ discard block |
||
587 | 587 | } |
588 | 588 | |
589 | 589 | public function isOverThreshold($score) { |
590 | - if(!$this->isPartnerEnabled()) return false; |
|
590 | + if (!$this->isPartnerEnabled()) return false; |
|
591 | 591 | |
592 | 592 | $threshold = $this->email_threshold; |
593 | 593 | |
@@ -640,7 +640,7 @@ discard block |
||
640 | 640 | return rtrim( |
641 | 641 | strtr( |
642 | 642 | base64_encode( |
643 | - hash('sha256', $this->id."::".$this->created_at, true) |
|
643 | + hash('sha256', $this->id . "::" . $this->created_at, true) |
|
644 | 644 | ), |
645 | 645 | '+/', '-_'), |
646 | 646 | '='); |