@@ -81,12 +81,12 @@ |
||
| 81 | 81 | protected function createAchievement(array $achievement) |
| 82 | 82 | { |
| 83 | 83 | DB::table('achievements')->insert( |
| 84 | - array_only($achievement, ['id', 'name', 'description', 'points', 'created_at', 'updated_at']) |
|
| 84 | + array_only($achievement, [ 'id', 'name', 'description', 'points', 'created_at', 'updated_at' ]) |
|
| 85 | 85 | ); |
| 86 | 86 | |
| 87 | - foreach ($achievement['criterias'] as $criteria) { |
|
| 87 | + foreach ($achievement[ 'criterias' ] as $criteria) { |
|
| 88 | 88 | DB::table('achievement_criterias')->insert( |
| 89 | - array_merge($criteria, ['achievement_id' => $achievement['id']]) |
|
| 89 | + array_merge($criteria, [ 'achievement_id' => $achievement[ 'id' ] ]) |
|
| 90 | 90 | ); |
| 91 | 91 | } |
| 92 | 92 | } |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('achievement_criterias', function (Blueprint $table) { |
|
| 16 | + Schema::create('achievement_criterias', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->unsignedInteger('achievement_id')->index(); |
| 19 | 19 | $table->string('type')->index(); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('achievementables', function (Blueprint $table) { |
|
| 16 | + Schema::create('achievementables', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('achievementable_type')->index(); |
| 19 | 19 | $table->unsignedInteger('achievementable_id')->index(); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('achievement_criteriables', function (Blueprint $table) { |
|
| 16 | + Schema::create('achievement_criteriables', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('achievement_criteriable_type')->index(); |
| 19 | 19 | $table->unsignedInteger('achievement_criteriable_id')->index(); |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | public function up() |
| 15 | 15 | { |
| 16 | - Schema::create('achievements', function (Blueprint $table) { |
|
| 16 | + Schema::create('achievements', function(Blueprint $table) { |
|
| 17 | 17 | $table->increments('id'); |
| 18 | 18 | $table->string('name')->nullable(); |
| 19 | 19 | $table->text('description')->nullable(); |
@@ -9,7 +9,7 @@ |
||
| 9 | 9 | * |
| 10 | 10 | * @var array |
| 11 | 11 | */ |
| 12 | - public $achievements = []; |
|
| 12 | + public $achievements = [ ]; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * AchievementsCompleted constructor. |
@@ -26,7 +26,7 @@ |
||
| 26 | 26 | { |
| 27 | 27 | $this->app->bind(AchievementsStorageInterface::class, AchievementsStorage::class); |
| 28 | 28 | |
| 29 | - $this->app->singleton(AchievementsManager::class, function () { |
|
| 29 | + $this->app->singleton(AchievementsManager::class, function() { |
|
| 30 | 30 | $storage = app(AchievementsStorageInterface::class); |
| 31 | 31 | |
| 32 | 32 | return new AchievementsManager($storage); |
@@ -60,7 +60,7 @@ |
||
| 60 | 60 | |
| 61 | 61 | $instance = app($criteria); |
| 62 | 62 | |
| 63 | - AchievementsManager::registerHandler($instance->type(), [$instance, 'handle']); |
|
| 63 | + AchievementsManager::registerHandler($instance->type(), [ $instance, 'handle' ]); |
|
| 64 | 64 | } |
| 65 | 65 | } |
| 66 | 66 | } |
@@ -27,14 +27,14 @@ discard block |
||
| 27 | 27 | $criterias = $this->getCriteriasByType($type); |
| 28 | 28 | |
| 29 | 29 | if (!count($criterias)) { |
| 30 | - return []; |
|
| 30 | + return [ ]; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($type) { |
|
| 33 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($type) { |
|
| 34 | 34 | $query->where('type', $type); |
| 35 | 35 | }); |
| 36 | 36 | |
| 37 | - return $criterias->map(function (AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 37 | + return $criterias->map(function(AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 38 | 38 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
| 39 | 39 | })->toArray(); |
| 40 | 40 | } |
@@ -52,7 +52,7 @@ discard block |
||
| 52 | 52 | { |
| 53 | 53 | $query = $owner->achievementCriterias(); |
| 54 | 54 | |
| 55 | - call_user_func_array($callback, [$query]); |
|
| 55 | + call_user_func_array($callback, [ $query ]); |
|
| 56 | 56 | |
| 57 | 57 | return $this->transformOwnerCriteriasToProgress($query->get()); |
| 58 | 58 | } |
@@ -78,12 +78,12 @@ discard block |
||
| 78 | 78 | */ |
| 79 | 79 | protected function transformOwnerCriteriasToProgress(Collection $criterias) |
| 80 | 80 | { |
| 81 | - return $criterias->keyBy('id')->map(function (AchievementCriteriaModel $criteria) { |
|
| 81 | + return $criterias->keyBy('id')->map(function(AchievementCriteriaModel $criteria) { |
|
| 82 | 82 | return new AchievementCriteriaProgress( |
| 83 | 83 | intval($criteria->pivot->value), |
| 84 | 84 | false, |
| 85 | 85 | intval($criteria->pivot->completed) === 1, |
| 86 | - is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [] |
|
| 86 | + is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [ ] |
|
| 87 | 87 | ); |
| 88 | 88 | }); |
| 89 | 89 | } |
@@ -103,12 +103,12 @@ discard block |
||
| 103 | 103 | 'achievement_id' => $criteria->achievement_id, |
| 104 | 104 | 'type' => $criteria->type, |
| 105 | 105 | 'name' => $criteria->name, |
| 106 | - 'requirements' => $criteria->requirements ?? [], |
|
| 106 | + 'requirements' => $criteria->requirements ?? [ ], |
|
| 107 | 107 | 'max_value' => $criteria->max_value, |
| 108 | 108 | ]; |
| 109 | 109 | |
| 110 | 110 | if (!is_null($progress)) { |
| 111 | - $data['progress'] = [ |
|
| 111 | + $data[ 'progress' ] = [ |
|
| 112 | 112 | 'value' => $progress->value, |
| 113 | 113 | 'changed' => false, |
| 114 | 114 | 'completed' => $progress->completed, |
@@ -128,14 +128,14 @@ discard block |
||
| 128 | 128 | */ |
| 129 | 129 | public function getAchievementsByCriterias(array $criterias) |
| 130 | 130 | { |
| 131 | - $achievementIds = array_map(function (AchievementCriteria $criteria) { |
|
| 131 | + $achievementIds = array_map(function(AchievementCriteria $criteria) { |
|
| 132 | 132 | return $criteria->achievementId(); |
| 133 | 133 | }, $criterias); |
| 134 | 134 | |
| 135 | 135 | $achievements = AchievementModel::whereIn('id', array_unique($achievementIds))->get(); |
| 136 | 136 | |
| 137 | 137 | if (!count($achievements)) { |
| 138 | - return []; |
|
| 138 | + return [ ]; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | return $this->transformAchievements($achievements, $criterias)->toArray(); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $achievements->load('criterias'); |
| 154 | 154 | |
| 155 | - return $achievements->map([$this, 'convertAchievementModelWithCriterias'])->toArray(); |
|
| 155 | + return $achievements->map([ $this, 'convertAchievementModelWithCriterias' ])->toArray(); |
|
| 156 | 156 | } |
| 157 | 157 | |
| 158 | 158 | /** |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | $achievement->load('criterias'); |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - $criterias = $achievement->criterias->map(function (AchievementCriteriaModel $criteria) { |
|
| 171 | + $criterias = $achievement->criterias->map(function(AchievementCriteriaModel $criteria) { |
|
| 172 | 172 | return $this->transformCriteriaWithProgress($criteria); |
| 173 | 173 | }); |
| 174 | 174 | |
@@ -185,7 +185,7 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | protected function transformAchievements(Collection $achievements, array $criterias) |
| 187 | 187 | { |
| 188 | - return $achievements->map(function (AchievementModel $achievement) use ($criterias) { |
|
| 188 | + return $achievements->map(function(AchievementModel $achievement) use ($criterias) { |
|
| 189 | 189 | return $this->transformSingleAchievement($achievement, $criterias); |
| 190 | 190 | }); |
| 191 | 191 | } |
@@ -200,14 +200,14 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | protected function transformSingleAchievement(AchievementModel $achievement, array $criterias) |
| 202 | 202 | { |
| 203 | - $achievementCriterias = array_filter($criterias, function (AchievementCriteria $criteria) use ($achievement) { |
|
| 203 | + $achievementCriterias = array_filter($criterias, function(AchievementCriteria $criteria) use ($achievement) { |
|
| 204 | 204 | return $criteria->achievementId() === $achievement->id; |
| 205 | 205 | }); |
| 206 | 206 | |
| 207 | 207 | // Since we're dealing with owner-related criterias (progress exists if owner has any value), |
| 208 | 208 | // we can simply count completed criterias & determine if achievement has been completed. |
| 209 | 209 | $completedCriteriasCount = array_sum( |
| 210 | - array_map(function (AchievementCriteria $criteria) { |
|
| 210 | + array_map(function(AchievementCriteria $criteria) { |
|
| 211 | 211 | return $criteria->completed() ? 1 : 0; |
| 212 | 212 | }, $achievementCriterias) |
| 213 | 213 | ); |
@@ -234,7 +234,7 @@ discard block |
||
| 234 | 234 | { |
| 235 | 235 | $collection = collect($achievements); |
| 236 | 236 | |
| 237 | - $index = $collection->search(function (Achievement $achievement) use ($criteria) { |
|
| 237 | + $index = $collection->search(function(Achievement $achievement) use ($criteria) { |
|
| 238 | 238 | return $achievement->id() === $criteria->achievementId(); |
| 239 | 239 | }); |
| 240 | 240 | |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | $criterias = AchievementCriteriaModel::whereIn('achievement_id', $achievementIds)->get(); |
| 262 | 262 | |
| 263 | 263 | if (!count($criterias)) { |
| 264 | - return []; |
|
| 264 | + return [ ]; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($criterias) { |
|
| 267 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($criterias) { |
|
| 268 | 268 | $query->whereIn('achievement_criteria_model_id', $criterias->pluck('id')); |
| 269 | 269 | }); |
| 270 | 270 | |
| 271 | - $achievementsCriterias = $criterias->map(function (AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 271 | + $achievementsCriterias = $criterias->map(function(AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 272 | 272 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
| 273 | 273 | }); |
| 274 | 274 | |
@@ -311,10 +311,10 @@ discard block |
||
| 311 | 311 | public function setAchievementsCompleted($owner, array $achievements) |
| 312 | 312 | { |
| 313 | 313 | $now = Carbon::now(); |
| 314 | - $patch = []; |
|
| 314 | + $patch = [ ]; |
|
| 315 | 315 | |
| 316 | 316 | foreach ($achievements as $achievement) { |
| 317 | - $patch[$achievement->id()] = ['completed_at' => $now]; |
|
| 317 | + $patch[ $achievement->id() ] = [ 'completed_at' => $now ]; |
|
| 318 | 318 | } |
| 319 | 319 | |
| 320 | 320 | $owner->achievements()->syncWithoutDetaching($patch); |