@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | $this->container->set('common\interfaces\UserBehaviorInterface', '\site\tests\_support\MockUserBehavior'); |
25 | 25 | $this->container->set('common\interfaces\QuestionInterface', '\site\tests\_support\MockQuestion'); |
26 | 26 | |
27 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
27 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
28 | 28 | return new \common\components\Time('America/Los_Angeles'); |
29 | 29 | }); |
30 | 30 | |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | |
41 | 41 | public function testGetLocalTime() |
42 | 42 | { |
43 | - $this->specify('getLocalTime should function correctly', function () { |
|
43 | + $this->specify('getLocalTime should function correctly', function() { |
|
44 | 44 | expect("getLocalTime should work with user's set time", $this->assertEquals($this->time->getLocalTime(), (new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format("Y-m-d H:i:s"))); |
45 | 45 | expect('getLocalTime should work with a custom timezone', $this->assertEquals($this->time->getLocalTime("UTC"), (new DateTime("now"))->format("Y-m-d H:i:s"))); |
46 | 46 | }); |
@@ -48,13 +48,13 @@ discard block |
||
48 | 48 | |
49 | 49 | public function testConvertLocalToUTC() |
50 | 50 | { |
51 | - $this->specify('convertLocalToUTC should function correctly', function () { |
|
51 | + $this->specify('convertLocalToUTC should function correctly', function() { |
|
52 | 52 | $la_tz = (new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format("Y-m-d H:i:s"); |
53 | 53 | |
54 | 54 | expect('convertLocalToUTC should convert a Los Angeles tz to UTC with the included time', $this->assertEquals($this->time->convertLocalToUTC($la_tz), (new DateTime("now"))->format("Y-m-d H:i:s"))); |
55 | 55 | expect('convertLocalToUTC should convert a Los Angeles tz to UTC without the included time', $this->assertEquals($this->time->convertLocalToUTC($la_tz, false), (new DateTime("now"))->format("Y-m-d"))); |
56 | 56 | // with UTC |
57 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
57 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
58 | 58 | return new \common\components\Time('UTC'); |
59 | 59 | }); |
60 | 60 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -67,14 +67,14 @@ discard block |
||
67 | 67 | |
68 | 68 | public function testConvertUTCToLocal() |
69 | 69 | { |
70 | - $this->specify('convertUTCToLocal should function correctly', function () { |
|
70 | + $this->specify('convertUTCToLocal should function correctly', function() { |
|
71 | 71 | $utc_tz = (new DateTime("now"))->format("Y-m-d H:i:s"); |
72 | 72 | |
73 | 73 | expect('convertUTCToLocal should convert a UTC tz to Los Angeles with the included timezone', $this->assertEquals((new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format(DateTime::ATOM), $this->time->convertUTCToLocal($utc_tz))); |
74 | 74 | expect('convertUTCToLocal should convert a UTC tz to Los Angeles without the included timezone', $this->assertEquals($this->time->convertUTCToLocal($utc_tz, false), (new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format("Y-m-d H:i:s"))); |
75 | 75 | |
76 | 76 | // with UTC |
77 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
77 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
78 | 78 | return new \common\components\Time('UTC'); |
79 | 79 | }); |
80 | 80 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -87,7 +87,7 @@ discard block |
||
87 | 87 | |
88 | 88 | public function testGetLocalDate() |
89 | 89 | { |
90 | - $this->specify('getLocalDate should function correctly', function () { |
|
90 | + $this->specify('getLocalDate should function correctly', function() { |
|
91 | 91 | expect("getLocalDate should correctly get the user's local date", $this->assertEquals($this->time->getLocalDate(), (new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format("Y-m-d"))); |
92 | 92 | expect("getLocalDate should correctly get the local date of a specified timezone", $this->assertEquals($this->time->getLocalDate("UTC"), (new DateTime("now", new DateTimeZone("UTC")))->format("Y-m-d"))); |
93 | 93 | }); |
@@ -109,7 +109,7 @@ discard block |
||
109 | 109 | expect('getUTCBookends should return false if there is a space at the end of the time string', $this->assertFalse($this->time->getUTCBookends('2016-05-30 00:00:00 '))); |
110 | 110 | expect('getUTCBookends should return UTC bookend times from the Los_Angeles tz', $this->assertEquals($this->time->getUTCBookends('2016-05-30'), ['2016-05-30 07:00:00', '2016-05-31 06:59:59'])); |
111 | 111 | // with UTC |
112 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
112 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
113 | 113 | return new \common\components\Time('UTC'); |
114 | 114 | }); |
115 | 115 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public function parse(string $time, string $format = 'Y-m-d') { |
29 | 29 | $dt = DateTime::createFromFormat($format, $time, new DateTimeZone($this->timezone)); |
30 | - if($dt) { |
|
30 | + if ($dt) { |
|
31 | 31 | // 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. |
32 | 32 | $dt->setTime(0, 0, 0); |
33 | 33 | $formatted = $dt->format($format); |
34 | - if($formatted === $time && $this->inBounds($dt)) { |
|
34 | + if ($formatted === $time && $this->inBounds($dt)) { |
|
35 | 35 | return $dt; |
36 | 36 | } |
37 | 37 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | $test = strtotime($dt->format('Y-m-d')); |
51 | 51 | $now = strtotime($this->getLocalDate()); |
52 | 52 | |
53 | - if($first <= $test && $test <= $now) { |
|
53 | + if ($first <= $test && $test <= $now) { |
|
54 | 54 | return true; |
55 | 55 | } else { |
56 | 56 | return false; |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | } |
75 | 75 | |
76 | 76 | public function getLocalTime($timezone = null) { |
77 | - if($timezone === null) |
|
77 | + if ($timezone === null) |
|
78 | 78 | $timezone = $this->timezone; |
79 | 79 | |
80 | 80 | $timestamp = new DateTime("now", new DateTimeZone($timezone)); |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | } |
83 | 83 | |
84 | 84 | public function getLocalDate($timezone = null) { |
85 | - if($timezone === null) |
|
85 | + if ($timezone === null) |
|
86 | 86 | $timezone = $this->timezone; |
87 | 87 | |
88 | 88 | return (new DateTime("now", new DateTimeZone($timezone))) |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | public function getUTCBookends($local) { |
98 | 98 | $local = trim($local); |
99 | - if(strpos($local, " ")) { |
|
99 | + if (strpos($local, " ")) { |
|
100 | 100 | return false; |
101 | 101 | } |
102 | 102 |
@@ -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,14 +49,14 @@ discard block |
||
49 | 49 | |
50 | 50 | // delete cached scores |
51 | 51 | $time = Yii::$container->get('common\interfaces\TimeInterface'); |
52 | - $key = "scores_of_last_month_".Yii::$app->user->id."_".$time->getLocalDate(); |
|
52 | + $key = "scores_of_last_month_" . Yii::$app->user->id . "_" . $time->getLocalDate(); |
|
53 | 53 | Yii::$app->cache->delete($key); |
54 | 54 | |
55 | 55 | // if the user has publicised their score graph, create the image |
56 | - if(Yii::$app->user->identity->expose_graph) { |
|
56 | + if (Yii::$app->user->identity->expose_graph) { |
|
57 | 57 | $user_behavior = Yii::$container->get('common\interfaces\UserBehaviorInterface'); |
58 | 58 | $scores_last_month = $user_behavior->calculateScoresOfLastMonth(); |
59 | - if($scores_last_month) { |
|
59 | + if ($scores_last_month) { |
|
60 | 60 | Yii::$container |
61 | 61 | ->get('common\components\Graph') |
62 | 62 | ->create($scores_last_month, true); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $date = Yii::$container->get('common\interfaces\TimeInterface')->getLocalDate(); |
82 | 82 | |
83 | 83 | $user_behaviors = $user_behavior->getUserBehaviorsWithCategory($date); |
84 | - if(count($user_behaviors) === 0) { |
|
84 | + if (count($user_behaviors) === 0) { |
|
85 | 85 | return $this->redirect(['view']); |
86 | 86 | } |
87 | 87 | |
@@ -91,10 +91,10 @@ discard block |
||
91 | 91 | $form->deleteToday(); |
92 | 92 | |
93 | 93 | $behaviors = $user_behavior->findAll($form->getUserBehaviorIds()); |
94 | - if($result = $form->saveAnswers($behaviors)) { |
|
94 | + if ($result = $form->saveAnswers($behaviors)) { |
|
95 | 95 | |
96 | 96 | $score = $user_behavior->getDailyScore(); |
97 | - if(Yii::$app->user->identity->isOverThreshold($score)) { |
|
97 | + if (Yii::$app->user->identity->isOverThreshold($score)) { |
|
98 | 98 | Yii::$app->user->identity->sendEmailReport($date); |
99 | 99 | Yii::$app->session->setFlash('warning', 'Your check-in is complete. A notification has been sent to your report partners because of your high score. Reach out to them!'); |
100 | 100 | } else { |
@@ -114,9 +114,9 @@ discard block |
||
114 | 114 | public function actionView(string $date = null) |
115 | 115 | { |
116 | 116 | $time = Yii::$container->get('common\interfaces\TimeInterface'); |
117 | - if(is_null($date)) { |
|
117 | + if (is_null($date)) { |
|
118 | 118 | $date = $time->getLocalDate(); |
119 | - } else if($dt = $time->parse($date)) { |
|
119 | + } else if ($dt = $time->parse($date)) { |
|
120 | 120 | $date = $dt->format('Y-m-d'); |
121 | 121 | } else { |
122 | 122 | $date = $time->getLocalDate(); |