@@ -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(); |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | public function achievements() |
| 22 | 22 | { |
| 23 | 23 | return $this->morphToMany(AchievementModel::class, 'achievementable') |
| 24 | - ->withPivot(['completed_at']); |
|
| 24 | + ->withPivot([ 'completed_at' ]); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | /** |
@@ -42,6 +42,6 @@ discard block |
||
| 42 | 42 | public function achievementCriterias() |
| 43 | 43 | { |
| 44 | 44 | return $this->morphToMany(AchievementCriteriaModel::class, 'achievement_criteriable') |
| 45 | - ->withPivot(['value', 'completed', 'updated_at']); |
|
| 45 | + ->withPivot([ 'value', 'completed', 'updated_at' ]); |
|
| 46 | 46 | } |
| 47 | 47 | } |
@@ -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. |
@@ -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,7 +78,7 @@ 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 | $criteria->pivot->value, |
| 84 | 84 | false, |
@@ -102,12 +102,12 @@ discard block |
||
| 102 | 102 | 'achievement_id' => $criteria->achievement_id, |
| 103 | 103 | 'type' => $criteria->type, |
| 104 | 104 | 'name' => $criteria->name, |
| 105 | - 'requirements' => $criteria->requirements ?? [], |
|
| 105 | + 'requirements' => $criteria->requirements ?? [ ], |
|
| 106 | 106 | 'max_value' => $criteria->max_value, |
| 107 | 107 | ]; |
| 108 | 108 | |
| 109 | 109 | if (!is_null($progress)) { |
| 110 | - $data['progress'] = [ |
|
| 110 | + $data[ 'progress' ] = [ |
|
| 111 | 111 | 'value' => $progress->value, |
| 112 | 112 | 'changed' => false, |
| 113 | 113 | 'completed' => $progress->completed, |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | public function getAchievementsByCriterias(array $criterias) |
| 128 | 128 | { |
| 129 | - $achievementIds = array_map(function (AchievementCriteria $criteria) { |
|
| 129 | + $achievementIds = array_map(function(AchievementCriteria $criteria) { |
|
| 130 | 130 | return $criteria->achievementId(); |
| 131 | 131 | }, $criterias); |
| 132 | 132 | |
| 133 | 133 | $achievements = AchievementModel::whereIn('id', array_unique($achievementIds))->get(); |
| 134 | 134 | |
| 135 | 135 | if (!count($achievements)) { |
| 136 | - return []; |
|
| 136 | + return [ ]; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | return $this->transformAchievements($achievements, $criterias)->toArray(); |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $achievements->load('criterias'); |
| 152 | 152 | |
| 153 | - return $achievements->map([$this, 'convertAchievementModelWithCriterias'])->toArray(); |
|
| 153 | + return $achievements->map([ $this, 'convertAchievementModelWithCriterias' ])->toArray(); |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | $achievement->load('criterias'); |
| 167 | 167 | } |
| 168 | 168 | |
| 169 | - $criterias = $achievement->criterias->map(function (AchievementCriteriaModel $criteria) { |
|
| 169 | + $criterias = $achievement->criterias->map(function(AchievementCriteriaModel $criteria) { |
|
| 170 | 170 | return $this->transformCriteriaWithProgress($criteria); |
| 171 | 171 | }); |
| 172 | 172 | |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | */ |
| 184 | 184 | protected function transformAchievements(Collection $achievements, array $criterias) |
| 185 | 185 | { |
| 186 | - return $achievements->map(function (AchievementModel $achievement) use ($criterias) { |
|
| 186 | + return $achievements->map(function(AchievementModel $achievement) use ($criterias) { |
|
| 187 | 187 | return $this->transformSingleAchievement($achievement, $criterias); |
| 188 | 188 | }); |
| 189 | 189 | } |
@@ -198,14 +198,14 @@ discard block |
||
| 198 | 198 | */ |
| 199 | 199 | protected function transformSingleAchievement(AchievementModel $achievement, array $criterias) |
| 200 | 200 | { |
| 201 | - $achievementCriterias = array_filter($criterias, function (AchievementCriteria $criteria) use ($achievement) { |
|
| 201 | + $achievementCriterias = array_filter($criterias, function(AchievementCriteria $criteria) use ($achievement) { |
|
| 202 | 202 | return $criteria->achievementId() === $achievement->id; |
| 203 | 203 | }); |
| 204 | 204 | |
| 205 | 205 | // Since we're dealing with owner-related criterias (progress exists if owner has any value), |
| 206 | 206 | // we can simply count completed criterias & determine if achievement has been completed. |
| 207 | 207 | $completedCriteriasCount = array_sum( |
| 208 | - array_map(function (AchievementCriteria $criteria) { |
|
| 208 | + array_map(function(AchievementCriteria $criteria) { |
|
| 209 | 209 | return $criteria->completed() ? 1 : 0; |
| 210 | 210 | }, $achievementCriterias) |
| 211 | 211 | ); |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | { |
| 233 | 233 | $collection = collect($achievements); |
| 234 | 234 | |
| 235 | - $index = $collection->search(function (Achievement $achievement) use ($criteria) { |
|
| 235 | + $index = $collection->search(function(Achievement $achievement) use ($criteria) { |
|
| 236 | 236 | return $achievement->id() === $criteria->achievementId(); |
| 237 | 237 | }); |
| 238 | 238 | |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | $criterias = AchievementCriteriaModel::whereIn('achievement_id', $achievementIds)->get(); |
| 260 | 260 | |
| 261 | 261 | if (!count($criterias)) { |
| 262 | - return []; |
|
| 262 | + return [ ]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($criterias) { |
|
| 265 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($criterias) { |
|
| 266 | 266 | $query->whereIn('achievement_criteria_model_id', $criterias->pluck('id')); |
| 267 | 267 | }); |
| 268 | 268 | |
| 269 | - $achievementsCriterias = $criterias->map(function (AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 269 | + $achievementsCriterias = $criterias->map(function(AchievementCriteriaModel $criteria) use ($ownerCriteriaProgress) { |
|
| 270 | 270 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
| 271 | 271 | }); |
| 272 | 272 | |
@@ -308,10 +308,10 @@ discard block |
||
| 308 | 308 | public function setAchievementsCompleted($owner, array $achievements) |
| 309 | 309 | { |
| 310 | 310 | $now = Carbon::now(); |
| 311 | - $patch = []; |
|
| 311 | + $patch = [ ]; |
|
| 312 | 312 | |
| 313 | 313 | foreach ($achievements as $achievement) { |
| 314 | - $patch[$achievement->id()] = ['completed_at' => $now]; |
|
| 314 | + $patch[ $achievement->id() ] = [ 'completed_at' => $now ]; |
|
| 315 | 315 | } |
| 316 | 316 | |
| 317 | 317 | $owner->achievements()->syncWithoutDetaching($patch); |
@@ -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); |