@@ -36,7 +36,7 @@ |
||
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | if (!empty($this->json)) { |
| 39 | - foreach($this->json[self::POS_READY] as $json_name => $json_value) { |
|
| 39 | + foreach ($this->json[self::POS_READY] as $json_name => $json_value) { |
|
| 40 | 40 | $lines[] = Html::script($json_value, ['type' => 'application/json', 'id' => $json_name]); |
| 41 | 41 | } |
| 42 | 42 | } |
@@ -33,8 +33,8 @@ |
||
| 33 | 33 | { |
| 34 | 34 | return [ |
| 35 | 35 | 'error' => [ |
| 36 | - 'class' => 'yii\web\ErrorAction', |
|
| 37 | - ], |
|
| 36 | + 'class' => 'yii\web\ErrorAction', |
|
| 37 | + ], |
|
| 38 | 38 | 'captcha' => [ |
| 39 | 39 | 'class' => 'yii\captcha\CaptchaAction', |
| 40 | 40 | ], |
@@ -60,10 +60,10 @@ |
||
| 60 | 60 | */ |
| 61 | 61 | public function login() |
| 62 | 62 | { |
| 63 | - if($this->validate()) { |
|
| 63 | + if ($this->validate()) { |
|
| 64 | 64 | $user = $this->getUser(); |
| 65 | - if($user->isVerified()) { |
|
| 66 | - return Yii::$app->user->login($user, $this->rememberMe ? 3600 * 24 * 30 : 0); |
|
| 65 | + if ($user->isVerified()) { |
|
| 66 | + return Yii::$app->user->login($user, $this->rememberMe ? 3600*24*30 : 0); |
|
| 67 | 67 | } else { |
| 68 | 68 | Yii::$app->session->setFlash('warning', 'You must verify your account before you can proceed. Please check your email inbox for a verification email and follow the instructions.'); |
| 69 | 69 | } |
@@ -12,13 +12,13 @@ |
||
| 12 | 12 | class Category extends \yii\base\BaseObject implements \common\interfaces\CategoryInterface { |
| 13 | 13 | |
| 14 | 14 | public static $categories = [ |
| 15 | - [ "id" => 1, "name" => "Restoration"], |
|
| 16 | - [ "id" => 2, "name" => "Forgetting Priorities"], |
|
| 17 | - [ "id" => 3, "name" => "Anxiety"], |
|
| 18 | - [ "id" => 4, "name" => "Speeding Up"], |
|
| 19 | - [ "id" => 5, "name" => "Ticked Off"], |
|
| 20 | - [ "id" => 6, "name" => "Exhausted"], |
|
| 21 | - [ "id" => 7, "name" => "Relapse/Moral Failure"], |
|
| 15 | + ["id" => 1, "name" => "Restoration"], |
|
| 16 | + ["id" => 2, "name" => "Forgetting Priorities"], |
|
| 17 | + ["id" => 3, "name" => "Anxiety"], |
|
| 18 | + ["id" => 4, "name" => "Speeding Up"], |
|
| 19 | + ["id" => 5, "name" => "Ticked Off"], |
|
| 20 | + ["id" => 6, "name" => "Exhausted"], |
|
| 21 | + ["id" => 7, "name" => "Relapse/Moral Failure"], |
|
| 22 | 22 | ]; |
| 23 | 23 | |
| 24 | 24 | public static $colors = [ |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | use \Codeception\Specify; |
| 15 | 15 | |
| 16 | 16 | private $user; |
| 17 | - private $filepath = __DIR__.'/../../_output/test_graph.png'; |
|
| 18 | - private $filepath_extra = __DIR__.'/../../_output/charts/test_graph.png'; |
|
| 17 | + private $filepath = __DIR__ . '/../../_output/test_graph.png'; |
|
| 18 | + private $filepath_extra = __DIR__ . '/../../_output/charts/test_graph.png'; |
|
| 19 | 19 | |
| 20 | 20 | public function setUp() { |
| 21 | 21 | $this->user = $this->getMockBuilder('\site\tests\_support\MockUser') |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | ->willReturn('random1DH4sh'); |
| 37 | 37 | $graph = new Graph($this->user); |
| 38 | 38 | |
| 39 | - expect('the expected graph image filepath will be returned', $this->assertEquals(dirname(dirname(dirname(dirname(__DIR__)))).'/site/web/charts/random1DH4sh.png', $graph->getFilepath())); |
|
| 39 | + expect('the expected graph image filepath will be returned', $this->assertEquals(dirname(dirname(dirname(dirname(__DIR__)))) . '/site/web/charts/random1DH4sh.png', $graph->getFilepath())); |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | public function testGetUrl() { |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | ->method('getFilepath') |
| 58 | 58 | ->willReturn($this->filepath); |
| 59 | 59 | |
| 60 | - if(!file_exists($this->filepath) && preg_match('%/_output/test_graph.png$%', $this->filepath)) { |
|
| 60 | + if (!file_exists($this->filepath) && preg_match('%/_output/test_graph.png$%', $this->filepath)) { |
|
| 61 | 61 | touch($this->filepath); |
| 62 | 62 | expect('just a check to be sure $filepath is sane', $this->assertStringEndsWith('/_output/test_graph.png', $this->filepath)); |
| 63 | 63 | expect('the generated file should exist', $this->assertFileExists($this->filepath)); |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | expect('the generated file should be readable', $this->assertFileExists($this->filepath_extra)); |
| 90 | 90 | |
| 91 | 91 | // cleanup |
| 92 | - if(file_exists($this->filepath_extra) && preg_match('%/_output/charts/test_graph.png%', $this->filepath_extra)) { |
|
| 92 | + if (file_exists($this->filepath_extra) && preg_match('%/_output/charts/test_graph.png%', $this->filepath_extra)) { |
|
| 93 | 93 | // just in case something is weird, we don't want to straight rm this file |
| 94 | 94 | unlink($this->filepath_extra); |
| 95 | 95 | rmdir(dirname($this->filepath_extra)); |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | } |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | -function checkinBreakdown () { |
|
| 100 | +function checkinBreakdown() { |
|
| 101 | 101 | return [ |
| 102 | 102 | '2019-01-31' => [], |
| 103 | 103 | '2019-02-01' => [], |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | '2019-02-27' => [], |
| 231 | 231 | '2019-02-28' => [], |
| 232 | 232 | '2019-03-01' => [ |
| 233 | - 2 => [ 'name' => 'Forgetting Priorities', |
|
| 233 | + 2 => ['name' => 'Forgetting Priorities', |
|
| 234 | 234 | 'count' => 6, |
| 235 | 235 | 'color' => '#4CA100', |
| 236 | 236 | 'highlight' => '#61B219', |
@@ -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; |
@@ -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, |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | public function getFilepath() { |
| 29 | 29 | $path = Yii::getAlias('@graphImgPath'); |
| 30 | 30 | $filename = $this->user->getIdHash() . ".png"; |
| 31 | - return $path. '/' . $filename; |
|
| 31 | + return $path . '/' . $filename; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string the encoded image |
| 62 | 62 | */ |
| 63 | 63 | public function create(array $checkins, bool $toDisk = false) { |
| 64 | - if($toDisk) { |
|
| 64 | + if ($toDisk) { |
|
| 65 | 65 | // wipe out the current image, if it exists |
| 66 | 66 | $this->destroy(); |
| 67 | 67 | } |
@@ -81,11 +81,11 @@ discard block |
||
| 81 | 81 | |
| 82 | 82 | // Setup dates as labels on the X-axis |
| 83 | 83 | $graph->xaxis->SetTickLabels(array_keys($checkins)); |
| 84 | - $graph->xaxis->HideTicks(false,false); |
|
| 84 | + $graph->xaxis->HideTicks(false, false); |
|
| 85 | 85 | |
| 86 | 86 | $graph->yaxis->scale->SetAutoMin(0); |
| 87 | 87 | $graph->yaxis->HideLine(false); |
| 88 | - $graph->yaxis->HideTicks(false,false); |
|
| 88 | + $graph->yaxis->HideTicks(false, false); |
|
| 89 | 89 | $graph->xaxis->SetLabelAngle(45); |
| 90 | 90 | $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 10); |
| 91 | 91 | $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 15); |
@@ -93,8 +93,8 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | // format the data into something nicer |
| 95 | 95 | $accum = []; |
| 96 | - foreach($checkins as $checkin_sum) { |
|
| 97 | - for($i = 1; $i <= 7; $i ++) { |
|
| 96 | + foreach ($checkins as $checkin_sum) { |
|
| 97 | + for ($i = 1; $i <= 7; $i++) { |
|
| 98 | 98 | $accum[$i][] = array_key_exists($i, $checkin_sum) ? $checkin_sum[$i]['count'] : 0; |
| 99 | 99 | } |
| 100 | 100 | } |
@@ -102,7 +102,7 @@ discard block |
||
| 102 | 102 | // Create the bar plots |
| 103 | 103 | $plots = []; |
| 104 | 104 | $category = Yii::$container->get(\common\interfaces\CategoryInterface::class); |
| 105 | - foreach($accum as $category_key => $category_data) { |
|
| 105 | + foreach ($accum as $category_key => $category_data) { |
|
| 106 | 106 | $bplot = new BarPlot($category_data); |
| 107 | 107 | $color = $category::$colors[$category_key]['color']; |
| 108 | 108 | |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | $graph->Add($gbbplot); |
| 118 | 118 | |
| 119 | 119 | $graph->legend->SetColumns(3); |
| 120 | - $graph->legend->SetPos(0.5,0.98,'center','bottom'); // position it at the center, just above the bottom edge |
|
| 120 | + $graph->legend->SetPos(0.5, 0.98, 'center', 'bottom'); // position it at the center, just above the bottom edge |
|
| 121 | 121 | |
| 122 | 122 | $img = $graph->Stroke(_IMG_HANDLER); |
| 123 | 123 | |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | imagepng($img); |
| 126 | 126 | $img_data = ob_get_clean(); |
| 127 | 127 | |
| 128 | - if($toDisk) { |
|
| 128 | + if ($toDisk) { |
|
| 129 | 129 | $filepath = $this->getFilepath(); |
| 130 | - if(!is_dir(dirname($filepath))) { |
|
| 130 | + if (!is_dir(dirname($filepath))) { |
|
| 131 | 131 | mkdir(dirname($filepath), 0766, true); |
| 132 | 132 | } |
| 133 | 133 | |
@@ -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 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | public function testGetLocalTime() |
| 49 | 49 | { |
| 50 | - $this->specify('getLocalTime should function correctly', function () { |
|
| 50 | + $this->specify('getLocalTime should function correctly', function() { |
|
| 51 | 51 | 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"))); |
| 52 | 52 | expect('getLocalTime should work with a custom timezone', $this->assertEquals($this->time->getLocalTime("UTC"), (new DateTime("now"))->format("Y-m-d H:i:s"))); |
| 53 | 53 | }); |
@@ -55,13 +55,13 @@ discard block |
||
| 55 | 55 | |
| 56 | 56 | public function testConvertLocalToUTC() |
| 57 | 57 | { |
| 58 | - $this->specify('convertLocalToUTC should function correctly', function () { |
|
| 58 | + $this->specify('convertLocalToUTC should function correctly', function() { |
|
| 59 | 59 | $la_tz = (new DateTime("now", new DateTimeZone("America/Los_Angeles")))->format("Y-m-d H:i:s"); |
| 60 | 60 | |
| 61 | 61 | 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"))); |
| 62 | 62 | 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"))); |
| 63 | 63 | // with UTC |
| 64 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 64 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 65 | 65 | return new \common\components\Time('UTC'); |
| 66 | 66 | }); |
| 67 | 67 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | public function testConvertUTCToLocal() |
| 76 | 76 | { |
| 77 | - $this->specify('convertUTCToLocal should function correctly', function () { |
|
| 77 | + $this->specify('convertUTCToLocal should function correctly', function() { |
|
| 78 | 78 | $utc_tz = (new DateTime("now"))->format("Y-m-d H:i:s"); |
| 79 | 79 | |
| 80 | 80 | 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))); |
| 81 | 81 | 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"))); |
| 82 | 82 | |
| 83 | 83 | // with UTC |
| 84 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 84 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 85 | 85 | return new \common\components\Time('UTC'); |
| 86 | 86 | }); |
| 87 | 87 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | |
| 95 | 95 | public function testGetLocalDate() |
| 96 | 96 | { |
| 97 | - $this->specify('getLocalDate should function correctly', function () { |
|
| 97 | + $this->specify('getLocalDate should function correctly', function() { |
|
| 98 | 98 | 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"))); |
| 99 | 99 | 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"))); |
| 100 | 100 | }); |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | 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 '))); |
| 117 | 117 | 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'])); |
| 118 | 118 | // with UTC |
| 119 | - $this->container->set('common\interfaces\TimeInterface', function () { |
|
| 119 | + $this->container->set('common\interfaces\TimeInterface', function() { |
|
| 120 | 120 | return new \common\components\Time('UTC'); |
| 121 | 121 | }); |
| 122 | 122 | $time = $this->container->get('common\interfaces\TimeInterface'); |
@@ -203,11 +203,11 @@ discard block |
||
| 203 | 203 | $tz = 'America/Los_Angeles'; |
| 204 | 204 | $this->time->timezone = 'America/Los_Angeles'; |
| 205 | 205 | |
| 206 | - $today = new \DateTime("now + 1 day", new \DateTimeZone($tz)); // we do an extra day to include today as the last day |
|
| 206 | + $today = new \DateTime("now + 1 day", new \DateTimeZone($tz)); // we do an extra day to include today as the last day |
|
| 207 | 207 | $should_be_today = $this->time->getDateTimesInPeriod()->getEndDate(); |
| 208 | 208 | expect('getDateTimesInPeriod should return a list of \DatePeriods, the last being for today', $this->assertEquals($today->format('Y-m-d H'), $should_be_today->format('Y-m-d H'))); |
| 209 | 209 | |
| 210 | - $start = new \DateTime("30 days ago", new \DateTimeZone($tz)); |
|
| 210 | + $start = new \DateTime("30 days ago", new \DateTimeZone($tz)); |
|
| 211 | 211 | $should_be_start = $this->time->getDateTimesInPeriod()->getStartDate(); |
| 212 | 212 | expect('getDateTimesInPeriod should return a list of \DatePeriods, the first being for 30 days ago (by default)', $this->assertEquals($start->format('Y-m-d H'), $should_be_start->format('Y-m-d H'))); |
| 213 | 213 | } |