@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @param array $args |
| 65 | 65 | * @return mixed |
| 66 | 66 | */ |
| 67 | - protected function dispatchEvent(string $type, array $args = []) |
|
| 67 | + protected function dispatchEvent(string $type, array $args = [ ]) |
|
| 68 | 68 | { |
| 69 | 69 | $className = $this->getConfigurableClassName('events', $type); |
| 70 | 70 | |
@@ -84,14 +84,14 @@ discard block |
||
| 84 | 84 | $criterias = $this->getCriteriasByType($type); |
| 85 | 85 | |
| 86 | 86 | if (!count($criterias)) { |
| 87 | - return []; |
|
| 87 | + return [ ]; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($type) { |
|
| 90 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($type) { |
|
| 91 | 91 | $query->where('type', $type); |
| 92 | 92 | }); |
| 93 | 93 | |
| 94 | - return $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
| 94 | + return $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
| 95 | 95 | /** @var AchievementCriteriaModel $criteria */ |
| 96 | 96 | |
| 97 | 97 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -111,7 +111,7 @@ discard block |
||
| 111 | 111 | { |
| 112 | 112 | $query = $owner->achievementCriterias(); |
| 113 | 113 | |
| 114 | - call_user_func_array($callback, [$query]); |
|
| 114 | + call_user_func_array($callback, [ $query ]); |
|
| 115 | 115 | |
| 116 | 116 | return $this->transformOwnerCriteriasToProgress($query->get()); |
| 117 | 117 | } |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | */ |
| 126 | 126 | protected function getCriteriasByType(string $type) |
| 127 | 127 | { |
| 128 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($type) { |
|
| 128 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($type) { |
|
| 129 | 129 | return $className::where('type', $type)->get(); |
| 130 | 130 | }); |
| 131 | 131 | } |
@@ -139,14 +139,14 @@ discard block |
||
| 139 | 139 | */ |
| 140 | 140 | protected function transformOwnerCriteriasToProgress(Collection $criterias) |
| 141 | 141 | { |
| 142 | - return $criterias->keyBy('id')->map(function ($criteria) { |
|
| 142 | + return $criterias->keyBy('id')->map(function($criteria) { |
|
| 143 | 143 | /** @var AchievementCriteriaModel $criteria */ |
| 144 | 144 | |
| 145 | 145 | return new AchievementCriteriaProgress( |
| 146 | 146 | intval($criteria->pivot->value), |
| 147 | 147 | false, |
| 148 | 148 | intval($criteria->pivot->completed) === 1, |
| 149 | - is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [] |
|
| 149 | + is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [ ] |
|
| 150 | 150 | ); |
| 151 | 151 | }); |
| 152 | 152 | } |
@@ -166,12 +166,12 @@ discard block |
||
| 166 | 166 | 'achievement_id' => $criteria->achievement_id, |
| 167 | 167 | 'type' => $criteria->type, |
| 168 | 168 | 'name' => $criteria->name, |
| 169 | - 'requirements' => $criteria->requirements ?? [], |
|
| 169 | + 'requirements' => $criteria->requirements ?? [ ], |
|
| 170 | 170 | 'max_value' => $criteria->max_value, |
| 171 | 171 | ]; |
| 172 | 172 | |
| 173 | 173 | if (!is_null($progress)) { |
| 174 | - $data['progress'] = [ |
|
| 174 | + $data[ 'progress' ] = [ |
|
| 175 | 175 | 'value' => $progress->value, |
| 176 | 176 | 'changed' => false, |
| 177 | 177 | 'completed' => $progress->completed, |
@@ -191,14 +191,14 @@ discard block |
||
| 191 | 191 | */ |
| 192 | 192 | public function getAchievementsByCriterias(array $criterias) |
| 193 | 193 | { |
| 194 | - $achievementIds = array_map(function (AchievementCriteria $criteria) { |
|
| 194 | + $achievementIds = array_map(function(AchievementCriteria $criteria) { |
|
| 195 | 195 | return $criteria->achievementId(); |
| 196 | 196 | }, $criterias); |
| 197 | 197 | |
| 198 | 198 | $achievements = $this->getAchievementsByIds(array_unique($achievementIds)); |
| 199 | 199 | |
| 200 | 200 | if (!count($achievements)) { |
| 201 | - return []; |
|
| 201 | + return [ ]; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | return $this->transformAchievements($achievements, $criterias)->toArray(); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | public function getAchievementsByIds(array $achievementIds) |
| 215 | 215 | { |
| 216 | - return $this->getModelClass(static::MODEL_ACHIEVEMENT, function (string $className) use ($achievementIds) { |
|
| 216 | + return $this->getModelClass(static::MODEL_ACHIEVEMENT, function(string $className) use ($achievementIds) { |
|
| 217 | 217 | return $className::whereIn('id', array_unique($achievementIds))->get(); |
| 218 | 218 | }); |
| 219 | 219 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | $achievements->load('criterias'); |
| 233 | 233 | } |
| 234 | 234 | |
| 235 | - return $achievements->map([$this, 'convertAchievementModelWithCriterias'])->toArray(); |
|
| 235 | + return $achievements->map([ $this, 'convertAchievementModelWithCriterias' ])->toArray(); |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -244,7 +244,7 @@ discard block |
||
| 244 | 244 | */ |
| 245 | 245 | public function convertAchievementModelWithCriterias($achievement) |
| 246 | 246 | { |
| 247 | - $criterias = $achievement->criterias->map(function ($criteria) { |
|
| 247 | + $criterias = $achievement->criterias->map(function($criteria) { |
|
| 248 | 248 | /** @var AchievementCriteriaModel $criteria */ |
| 249 | 249 | |
| 250 | 250 | return $this->transformCriteriaWithProgress($criteria); |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | */ |
| 264 | 264 | protected function transformAchievements(Collection $achievements, array $criterias) |
| 265 | 265 | { |
| 266 | - return $achievements->map(function ($achievement) use ($criterias) { |
|
| 266 | + return $achievements->map(function($achievement) use ($criterias) { |
|
| 267 | 267 | /** @var AchievementModel $achievement */ |
| 268 | 268 | |
| 269 | 269 | return $this->transformSingleAchievement($achievement, $criterias); |
@@ -280,14 +280,14 @@ discard block |
||
| 280 | 280 | */ |
| 281 | 281 | protected function transformSingleAchievement($achievement, array $criterias) |
| 282 | 282 | { |
| 283 | - $achievementCriterias = array_filter($criterias, function (AchievementCriteria $criteria) use ($achievement) { |
|
| 283 | + $achievementCriterias = array_filter($criterias, function(AchievementCriteria $criteria) use ($achievement) { |
|
| 284 | 284 | return $criteria->achievementId() === $achievement->id; |
| 285 | 285 | }); |
| 286 | 286 | |
| 287 | 287 | // Since we're dealing with owner-related criterias (progress exists if owner has any value), |
| 288 | 288 | // we can simply count completed criterias & determine if achievement has been completed. |
| 289 | 289 | $completedCriteriasCount = array_sum( |
| 290 | - array_map(function (AchievementCriteria $criteria) { |
|
| 290 | + array_map(function(AchievementCriteria $criteria) { |
|
| 291 | 291 | return $criteria->completed() ? 1 : 0; |
| 292 | 292 | }, $achievementCriterias) |
| 293 | 293 | ); |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | { |
| 315 | 315 | $collection = collect($achievements); |
| 316 | 316 | |
| 317 | - $index = $collection->search(function (Achievement $achievement) use ($criteria) { |
|
| 317 | + $index = $collection->search(function(Achievement $achievement) use ($criteria) { |
|
| 318 | 318 | return $achievement->id() === $criteria->achievementId(); |
| 319 | 319 | }); |
| 320 | 320 | |
@@ -338,14 +338,14 @@ discard block |
||
| 338 | 338 | $criterias = $this->getCriteriasByAchievementIds($achievementIds); |
| 339 | 339 | |
| 340 | 340 | if (!count($criterias)) { |
| 341 | - return []; |
|
| 341 | + return [ ]; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($criterias) { |
|
| 344 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($criterias) { |
|
| 345 | 345 | $query->whereIn('achievement_criteria_model_id', $criterias->pluck('id')); |
| 346 | 346 | }); |
| 347 | 347 | |
| 348 | - $achievementsCriterias = $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
| 348 | + $achievementsCriterias = $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
| 349 | 349 | /** @var AchievementCriteriaModel $criteria */ |
| 350 | 350 | |
| 351 | 351 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -363,7 +363,7 @@ discard block |
||
| 363 | 363 | */ |
| 364 | 364 | public function getCriteriasByAchievementIds(array $achievementIds) |
| 365 | 365 | { |
| 366 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($achievementIds) { |
|
| 366 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($achievementIds) { |
|
| 367 | 367 | return $className::whereIn('achievement_id', $achievementIds)->get(); |
| 368 | 368 | }); |
| 369 | 369 | } |
@@ -388,7 +388,7 @@ discard block |
||
| 388 | 388 | ], |
| 389 | 389 | ]); |
| 390 | 390 | |
| 391 | - $this->dispatchEvent('criteria_updated', [$owner, $criteria, $achievement, $progress]); |
|
| 391 | + $this->dispatchEvent('criteria_updated', [ $owner, $criteria, $achievement, $progress ]); |
|
| 392 | 392 | |
| 393 | 393 | return true; |
| 394 | 394 | } |
@@ -404,15 +404,15 @@ discard block |
||
| 404 | 404 | public function setAchievementsCompleted($owner, array $achievements) |
| 405 | 405 | { |
| 406 | 406 | $now = Carbon::now(); |
| 407 | - $patch = []; |
|
| 407 | + $patch = [ ]; |
|
| 408 | 408 | |
| 409 | 409 | foreach ($achievements as $achievement) { |
| 410 | - $patch[$achievement->id()] = ['completed_at' => $now]; |
|
| 410 | + $patch[ $achievement->id() ] = [ 'completed_at' => $now ]; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | $owner->achievements()->syncWithoutDetaching($patch); |
| 414 | 414 | |
| 415 | - $this->dispatchEvent('achievements_completed', [$owner, $achievements]); |
|
| 415 | + $this->dispatchEvent('achievements_completed', [ $owner, $achievements ]); |
|
| 416 | 416 | |
| 417 | 417 | return true; |
| 418 | 418 | } |