@@ -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 = [ |
@@ -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 | |
@@ -126,13 +126,13 @@ discard block |
||
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | public function getCheckinBreakdown(\DatePeriod $datetimes) { |
| 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 | 131 | |
| 132 | - if($scores === false) { |
|
| 132 | + if ($scores === false) { |
|
| 133 | 133 | $scores = []; |
| 134 | 134 | $count = 0; |
| 135 | - foreach($datetimes as $datetime) { |
|
| 135 | + foreach ($datetimes as $datetime) { |
|
| 136 | 136 | $count += 1; |
| 137 | 137 | $behaviors = self::decorateWithCategory($this->getBehaviorsWithCounts($datetime)); |
| 138 | 138 | $scores[$datetime->format('Y-m-d')] = $this->getBehaviorsByCategory($behaviors); |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | public function getBehaviorsByCategory(array $decorated_behaviors) { |
| 160 | 160 | $arr = array_reduce($decorated_behaviors, function($acc, $row) { |
| 161 | 161 | $cat_id = $row['behavior']['category']['id']; |
| 162 | - if(array_key_exists($cat_id, $acc)) { |
|
| 162 | + if (array_key_exists($cat_id, $acc)) { |
|
| 163 | 163 | $acc[$cat_id]['count'] += $row['count']; |
| 164 | 164 | } else { |
| 165 | 165 | $acc[$cat_id] = [ |
@@ -176,10 +176,10 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | public static function decorate(array $uo, $with_category = false) { |
| 179 | - foreach($uo as &$o) { |
|
| 180 | - if($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 179 | + foreach ($uo as &$o) { |
|
| 180 | + if ($behavior = \common\models\Behavior::getBehavior('id', $o['behavior_id'])) { |
|
| 181 | 181 | $o['behavior'] = $behavior; |
| 182 | - if($with_category) { |
|
| 182 | + if ($with_category) { |
|
| 183 | 183 | $o['behavior']['category'] = \common\models\Category::getCategory('id', $o['behavior']['category_id']); |
| 184 | 184 | } |
| 185 | 185 | } |
@@ -200,11 +200,11 @@ discard block |
||
| 200 | 200 | ->having('user_id = :user_id') |
| 201 | 201 | ->orderBy('count DESC'); |
| 202 | 202 | |
| 203 | - if($limit instanceof \DateTime) { |
|
| 203 | + if ($limit instanceof \DateTime) { |
|
| 204 | 204 | list($start, $end) = $this->time->getUTCBookends($limit->format('Y-m-d')); |
| 205 | 205 | $query->params += [':start_date' => $start, ':end_date' => $end]; |
| 206 | 206 | $query->where('user_id=:user_id AND date > :start_date AND date <= :end_date'); |
| 207 | - } else if(is_int($limit)) { |
|
| 207 | + } else if (is_int($limit)) { |
|
| 208 | 208 | $query->limit($limit); |
| 209 | 209 | } |
| 210 | 210 | |
@@ -10,8 +10,8 @@ discard block |
||
| 10 | 10 | 'common\interfaces\QuestionInterface' => \common\models\Question::class, |
| 11 | 11 | 'common\interfaces\BehaviorInterface' => \common\models\Behavior::class, |
| 12 | 12 | 'common\interfaces\CategoryInterface' => \common\models\Category::class, |
| 13 | - 'common\interfaces\TimeInterface' => function () { |
|
| 14 | - if(Yii::$app->user->getIsGuest()) { |
|
| 13 | + 'common\interfaces\TimeInterface' => function() { |
|
| 14 | + if (Yii::$app->user->getIsGuest()) { |
|
| 15 | 15 | return new \common\components\Time('UTC'); |
| 16 | 16 | } else { |
| 17 | 17 | return new \common\components\Time(Yii::$app->user->identity->timezone); |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | ], |
| 29 | 29 | 'components' => [ |
| 30 | 30 | // by default, sessions are stored in a local file |
| 31 | - 'cache' => [ // DummyCache never actually caches anything |
|
| 31 | + 'cache' => [// DummyCache never actually caches anything |
|
| 32 | 32 | 'class'=> yii\caching\DummyCache::class, |
| 33 | 33 | ], |
| 34 | 34 | 'mailer' => [ |
@@ -36,13 +36,13 @@ discard block |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 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 |
||
| 130 | 130 | * @return string a date string |
| 131 | 131 | */ |
| 132 | 132 | public function validate($date = null) { |
| 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(); |
@@ -151,12 +151,12 @@ discard block |
||
| 151 | 151 | $dt = new DateTime("now", new DateTimeZone($this->timezone)); |
| 152 | 152 | $dt2 = new DateTime("now", new DateTimeZone($this->timezone)); |
| 153 | 153 | $end = $dt->add(new \DateInterval('P1D')) // add a day, so the end date gets included in the intervals |
| 154 | - ->add(new \DateInterval('PT2M')); // to be sure we have everything |
|
| 154 | + ->add(new \DateInterval('PT2M')); // to be sure we have everything |
|
| 155 | 155 | $start = $dt2->add(new \DateInterval('PT2M')); // to be sure we have everything |
| 156 | 156 | $start = $start->sub(new \DateInterval("P${period}D")); |
| 157 | 157 | $periods = new \DatePeriod($start, new \DateInterval('P1D'), $end, \DatePeriod::EXCLUDE_START_DATE); |
| 158 | 158 | $local_tz = new \DateTimeZone($this->timezone); |
| 159 | - foreach($periods as $period) { |
|
| 159 | + foreach ($periods as $period) { |
|
| 160 | 160 | $period->setTimezone($local_tz); |
| 161 | 161 | } |
| 162 | 162 | return $periods; |
@@ -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,14 +61,14 @@ 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 | } |
| 68 | 68 | |
| 69 | 69 | $accum = []; |
| 70 | - foreach($checkins as $checkin_sum) { |
|
| 71 | - for($i = 1; $i <= 7; $i ++) { |
|
| 70 | + foreach ($checkins as $checkin_sum) { |
|
| 71 | + for ($i = 1; $i <= 7; $i++) { |
|
| 72 | 72 | $accum[$i][] = array_key_exists($i, $checkin_sum) ? $checkin_sum[$i]['count'] : 0; |
| 73 | 73 | } |
| 74 | 74 | } |
@@ -87,10 +87,10 @@ discard block |
||
| 87 | 87 | |
| 88 | 88 | // Setup dates as labels on the X-axis |
| 89 | 89 | $graph->xaxis->SetTickLabels(array_keys($checkins)); |
| 90 | - $graph->xaxis->HideTicks(false,false); |
|
| 90 | + $graph->xaxis->HideTicks(false, false); |
|
| 91 | 91 | $graph->yaxis->scale->SetAutoMin(0); |
| 92 | 92 | $graph->yaxis->HideLine(false); |
| 93 | - $graph->yaxis->HideTicks(false,false); |
|
| 93 | + $graph->yaxis->HideTicks(false, false); |
|
| 94 | 94 | $graph->xaxis->SetLabelAngle(45); |
| 95 | 95 | $graph->xaxis->SetFont(FF_ARIAL, FS_NORMAL, 10); |
| 96 | 96 | $graph->yaxis->SetFont(FF_ARIAL, FS_NORMAL, 15); |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | |
| 100 | 100 | // Create the bar plots |
| 101 | 101 | $plots = []; |
| 102 | - foreach($accum as $category_key => $category_data) { |
|
| 102 | + foreach ($accum as $category_key => $category_data) { |
|
| 103 | 103 | $bplot = new BarPlot($category_data); |
| 104 | 104 | $color = $category::$colors[$category_key]['color']; |
| 105 | 105 | |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | |
| 116 | 116 | // $graph->legend->SetFrameWeight(1); |
| 117 | 117 | $graph->legend->SetColumns(3); |
| 118 | - $graph->legend->SetColor('#4E4E4E','#00A78A'); |
|
| 118 | + $graph->legend->SetColor('#4E4E4E', '#00A78A'); |
|
| 119 | 119 | |
| 120 | 120 | $graph->title->SetFont(FF_ARIAL, FS_BOLD, 20); |
| 121 | 121 | $graph->title->Set("Behaviors broken down by Category"); |
@@ -145,9 +145,9 @@ discard block |
||
| 145 | 145 | imagepng($img); |
| 146 | 146 | $img_data = ob_get_clean(); |
| 147 | 147 | |
| 148 | - if($toDisk) { |
|
| 148 | + if ($toDisk) { |
|
| 149 | 149 | $filepath = $this->getFilepath(); |
| 150 | - if(!is_dir(dirname($filepath))) { |
|
| 150 | + if (!is_dir(dirname($filepath))) { |
|
| 151 | 151 | mkdir(dirname($filepath), 0766, true); |
| 152 | 152 | } |
| 153 | 153 | |
@@ -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', |
@@ -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", |
@@ -86,7 +86,7 @@ discard block |
||
| 86 | 86 | // generate scores graph image |
| 87 | 87 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 88 | 88 | $checkins_last_month = (Yii::$container->get(\common\interfaces\UserBehaviorInterface::class)) |
| 89 | - ->getCheckInBreakdown($time->getDateTimesInPeriod()); |
|
| 89 | + ->getCheckInBreakdown($time->getDateTimesInPeriod()); |
|
| 90 | 90 | |
| 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 |
@@ -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; |
@@ -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,11 +139,11 @@ 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 | $time = Yii::$container->get(\common\interfaces\TimeInterface::class); |
| 144 | 144 | $checkins_last_month = $this->user_behavior->getCheckInBreakdown($time->getDateTimesInPeriod()); |
| 145 | 145 | |
| 146 | - if($checkins_last_month) { |
|
| 146 | + if ($checkins_last_month) { |
|
| 147 | 147 | Yii::$container |
| 148 | 148 | ->get(\common\components\Graph::class, [Yii::$app->user->identity]) |
| 149 | 149 | ->create($checkins_last_month, true); |
@@ -6,22 +6,22 @@ discard block |
||
| 6 | 6 | use \site\models\EditProfileForm; |
| 7 | 7 | |
| 8 | 8 | class EditProfileFormTest extends \Codeception\Test\Unit { |
| 9 | - public $graph; |
|
| 10 | - public $values = [ |
|
| 11 | - 'timezone' => 'America/Los_Angeles', |
|
| 9 | + public $graph; |
|
| 10 | + public $values = [ |
|
| 11 | + 'timezone' => 'America/Los_Angeles', |
|
| 12 | 12 | 'send_email' => true, |
| 13 | - 'partner_email1' => '[email protected]', |
|
| 14 | - 'partner_email2' => '[email protected]', |
|
| 15 | - 'partner_email3' => '[email protected]', |
|
| 16 | - 'expose_graph' => true, |
|
| 17 | - ]; |
|
| 13 | + 'partner_email1' => '[email protected]', |
|
| 14 | + 'partner_email2' => '[email protected]', |
|
| 15 | + 'partner_email3' => '[email protected]', |
|
| 16 | + 'expose_graph' => true, |
|
| 17 | + ]; |
|
| 18 | 18 | |
| 19 | - public function setUp() { |
|
| 20 | - $this->graph = $this->getMockBuilder(common\components\Graph::class) |
|
| 21 | - ->setMethods(['create', 'destroy']) |
|
| 22 | - ->getMock(); |
|
| 23 | - parent::setUp(); |
|
| 24 | - } |
|
| 19 | + public function setUp() { |
|
| 20 | + $this->graph = $this->getMockBuilder(common\components\Graph::class) |
|
| 21 | + ->setMethods(['create', 'destroy']) |
|
| 22 | + ->getMock(); |
|
| 23 | + parent::setUp(); |
|
| 24 | + } |
|
| 25 | 25 | |
| 26 | 26 | public function testLoadUser() { |
| 27 | 27 | $user = $this->getUser(); |
@@ -51,20 +51,20 @@ discard block |
||
| 51 | 51 | $form->attributes = $this->values; |
| 52 | 52 | expect('saveProfile should return the user', $this->assertEquals($user, $form->saveProfile())); |
| 53 | 53 | return true; |
| 54 | - expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 54 | + expect('saveProfile should set the user\'s attributes to be the form values', $this->assertEquals($this->values, $user->attributes)); |
|
| 55 | 55 | |
| 56 | 56 | $form->send_email = 'not_a_boolean'; |
| 57 | 57 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertNull($form->saveProfile())); |
| 58 | 58 | |
| 59 | - $null_vals = [ |
|
| 60 | - 'partner_email1' => null, |
|
| 61 | - 'partner_email2' => null, |
|
| 62 | - 'partner_email3' => null, |
|
| 59 | + $null_vals = [ |
|
| 60 | + 'partner_email1' => null, |
|
| 61 | + 'partner_email2' => null, |
|
| 62 | + 'partner_email3' => null, |
|
| 63 | 63 | 'send_email' => null, |
| 64 | - 'timezone' => 'America/Los_Angeles', |
|
| 65 | - ]; |
|
| 64 | + 'timezone' => 'America/Los_Angeles', |
|
| 65 | + ]; |
|
| 66 | 66 | $form->send_email = false; |
| 67 | - $ret = $form->saveProfile(); |
|
| 67 | + $ret = $form->saveProfile(); |
|
| 68 | 68 | expect('saveProfile should return the user with the partner-related settings equal to null', $this->assertEquals($null_vals, $user->attributes)); |
| 69 | 69 | |
| 70 | 70 | $form->send_email = 'not_a_boolean'; |
@@ -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; |