@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | * @param Achievement $achievement |
379 | 379 | * @param AchievementCriteriaProgress $progress |
380 | 380 | * |
381 | - * @return mixed |
|
381 | + * @return boolean |
|
382 | 382 | */ |
383 | 383 | public function setCriteriaProgressUpdated($owner, AchievementCriteria $criteria, Achievement $achievement, AchievementCriteriaProgress $progress) |
384 | 384 | { |
@@ -401,7 +401,7 @@ discard block |
||
401 | 401 | * @param mixed $owner |
402 | 402 | * @param array $achievements |
403 | 403 | * |
404 | - * @return mixed |
|
404 | + * @return boolean |
|
405 | 405 | */ |
406 | 406 | public function setAchievementsCompleted($owner, array $achievements) |
407 | 407 | { |
@@ -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 | |
@@ -85,14 +85,14 @@ discard block |
||
85 | 85 | $criterias = $this->getCriteriasByType($type, $data); |
86 | 86 | |
87 | 87 | if (!count($criterias)) { |
88 | - return []; |
|
88 | + return [ ]; |
|
89 | 89 | } |
90 | 90 | |
91 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($type) { |
|
91 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($type) { |
|
92 | 92 | $query->where('type', $type); |
93 | 93 | }); |
94 | 94 | |
95 | - return $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
95 | + return $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
96 | 96 | /** @var AchievementCriteriaModel $criteria */ |
97 | 97 | |
98 | 98 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | { |
113 | 113 | $query = $owner->achievementCriterias(); |
114 | 114 | |
115 | - call_user_func_array($callback, [$query]); |
|
115 | + call_user_func_array($callback, [ $query ]); |
|
116 | 116 | |
117 | 117 | return $this->transformOwnerCriteriasToProgress($query->get()); |
118 | 118 | } |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | */ |
128 | 128 | protected function getCriteriasByType(string $type, $data = null) |
129 | 129 | { |
130 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($type) { |
|
130 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($type) { |
|
131 | 131 | return $className::where('type', $type)->get(); |
132 | 132 | }); |
133 | 133 | } |
@@ -141,14 +141,14 @@ discard block |
||
141 | 141 | */ |
142 | 142 | protected function transformOwnerCriteriasToProgress(Collection $criterias) |
143 | 143 | { |
144 | - return $criterias->keyBy('id')->map(function ($criteria) { |
|
144 | + return $criterias->keyBy('id')->map(function($criteria) { |
|
145 | 145 | /** @var AchievementCriteriaModel $criteria */ |
146 | 146 | |
147 | 147 | return new AchievementCriteriaProgress( |
148 | 148 | intval($criteria->pivot->value), |
149 | 149 | false, |
150 | 150 | intval($criteria->pivot->completed) === 1, |
151 | - is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [] |
|
151 | + is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [ ] |
|
152 | 152 | ); |
153 | 153 | }); |
154 | 154 | } |
@@ -168,12 +168,12 @@ discard block |
||
168 | 168 | 'achievement_id' => $criteria->achievement_id, |
169 | 169 | 'type' => $criteria->type, |
170 | 170 | 'name' => $criteria->name, |
171 | - 'requirements' => $criteria->requirements ?? [], |
|
171 | + 'requirements' => $criteria->requirements ?? [ ], |
|
172 | 172 | 'max_value' => $criteria->max_value, |
173 | 173 | ]; |
174 | 174 | |
175 | 175 | if (!is_null($progress)) { |
176 | - $data['progress'] = [ |
|
176 | + $data[ 'progress' ] = [ |
|
177 | 177 | 'value' => $progress->value, |
178 | 178 | 'changed' => false, |
179 | 179 | 'completed' => $progress->completed, |
@@ -193,14 +193,14 @@ discard block |
||
193 | 193 | */ |
194 | 194 | public function getAchievementsByCriterias(array $criterias) |
195 | 195 | { |
196 | - $achievementIds = array_map(function (AchievementCriteria $criteria) { |
|
196 | + $achievementIds = array_map(function(AchievementCriteria $criteria) { |
|
197 | 197 | return $criteria->achievementId(); |
198 | 198 | }, $criterias); |
199 | 199 | |
200 | 200 | $achievements = $this->getAchievementsByIds(array_unique($achievementIds)); |
201 | 201 | |
202 | 202 | if (!count($achievements)) { |
203 | - return []; |
|
203 | + return [ ]; |
|
204 | 204 | } |
205 | 205 | |
206 | 206 | return $this->transformAchievements($achievements, $criterias)->toArray(); |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | */ |
216 | 216 | public function getAchievementsByIds(array $achievementIds) |
217 | 217 | { |
218 | - return $this->getModelClass(static::MODEL_ACHIEVEMENT, function (string $className) use ($achievementIds) { |
|
218 | + return $this->getModelClass(static::MODEL_ACHIEVEMENT, function(string $className) use ($achievementIds) { |
|
219 | 219 | return $className::whereIn('id', array_unique($achievementIds))->get(); |
220 | 220 | }); |
221 | 221 | } |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | $achievements->load('criterias'); |
235 | 235 | } |
236 | 236 | |
237 | - return $achievements->map([$this, 'convertAchievementModelWithCriterias'])->toArray(); |
|
237 | + return $achievements->map([ $this, 'convertAchievementModelWithCriterias' ])->toArray(); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | */ |
247 | 247 | public function convertAchievementModelWithCriterias($achievement) |
248 | 248 | { |
249 | - $criterias = $achievement->criterias->map(function ($criteria) { |
|
249 | + $criterias = $achievement->criterias->map(function($criteria) { |
|
250 | 250 | /** @var AchievementCriteriaModel $criteria */ |
251 | 251 | |
252 | 252 | return $this->transformCriteriaWithProgress($criteria); |
@@ -265,7 +265,7 @@ discard block |
||
265 | 265 | */ |
266 | 266 | protected function transformAchievements(Collection $achievements, array $criterias) |
267 | 267 | { |
268 | - return $achievements->map(function ($achievement) use ($criterias) { |
|
268 | + return $achievements->map(function($achievement) use ($criterias) { |
|
269 | 269 | /** @var AchievementModel $achievement */ |
270 | 270 | |
271 | 271 | return $this->transformSingleAchievement($achievement, $criterias); |
@@ -282,14 +282,14 @@ discard block |
||
282 | 282 | */ |
283 | 283 | protected function transformSingleAchievement($achievement, array $criterias) |
284 | 284 | { |
285 | - $achievementCriterias = array_filter($criterias, function (AchievementCriteria $criteria) use ($achievement) { |
|
285 | + $achievementCriterias = array_filter($criterias, function(AchievementCriteria $criteria) use ($achievement) { |
|
286 | 286 | return $criteria->achievementId() === $achievement->id; |
287 | 287 | }); |
288 | 288 | |
289 | 289 | // Since we're dealing with owner-related criterias (progress exists if owner has any value), |
290 | 290 | // we can simply count completed criterias & determine if achievement has been completed. |
291 | 291 | $completedCriteriasCount = array_sum( |
292 | - array_map(function (AchievementCriteria $criteria) { |
|
292 | + array_map(function(AchievementCriteria $criteria) { |
|
293 | 293 | return $criteria->completed() ? 1 : 0; |
294 | 294 | }, $achievementCriterias) |
295 | 295 | ); |
@@ -316,7 +316,7 @@ discard block |
||
316 | 316 | { |
317 | 317 | $collection = collect($achievements); |
318 | 318 | |
319 | - $index = $collection->search(function (Achievement $achievement) use ($criteria) { |
|
319 | + $index = $collection->search(function(Achievement $achievement) use ($criteria) { |
|
320 | 320 | return $achievement->id() === $criteria->achievementId(); |
321 | 321 | }); |
322 | 322 | |
@@ -340,14 +340,14 @@ discard block |
||
340 | 340 | $criterias = $this->getCriteriasByAchievementIds($achievementIds); |
341 | 341 | |
342 | 342 | if (!count($criterias)) { |
343 | - return []; |
|
343 | + return [ ]; |
|
344 | 344 | } |
345 | 345 | |
346 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($criterias) { |
|
346 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($criterias) { |
|
347 | 347 | $query->whereIn('achievement_criteria_model_id', $criterias->pluck('id')); |
348 | 348 | }); |
349 | 349 | |
350 | - $achievementsCriterias = $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
350 | + $achievementsCriterias = $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
351 | 351 | /** @var AchievementCriteriaModel $criteria */ |
352 | 352 | |
353 | 353 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -365,7 +365,7 @@ discard block |
||
365 | 365 | */ |
366 | 366 | public function getCriteriasByAchievementIds(array $achievementIds) |
367 | 367 | { |
368 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($achievementIds) { |
|
368 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($achievementIds) { |
|
369 | 369 | return $className::whereIn('achievement_id', $achievementIds)->get(); |
370 | 370 | }); |
371 | 371 | } |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | ], |
391 | 391 | ]); |
392 | 392 | |
393 | - $this->dispatchEvent('criteria_updated', [$owner, $criteria, $achievement, $progress]); |
|
393 | + $this->dispatchEvent('criteria_updated', [ $owner, $criteria, $achievement, $progress ]); |
|
394 | 394 | |
395 | 395 | return true; |
396 | 396 | } |
@@ -406,15 +406,15 @@ discard block |
||
406 | 406 | public function setAchievementsCompleted($owner, array $achievements) |
407 | 407 | { |
408 | 408 | $now = Carbon::now(); |
409 | - $patch = []; |
|
409 | + $patch = [ ]; |
|
410 | 410 | |
411 | 411 | foreach ($achievements as $achievement) { |
412 | - $patch[$achievement->id()] = ['completed_at' => $now]; |
|
412 | + $patch[ $achievement->id() ] = [ 'completed_at' => $now ]; |
|
413 | 413 | } |
414 | 414 | |
415 | 415 | $owner->achievements()->syncWithoutDetaching($patch); |
416 | 416 | |
417 | - $this->dispatchEvent('achievements_completed', [$owner, $achievements]); |
|
417 | + $this->dispatchEvent('achievements_completed', [ $owner, $achievements ]); |
|
418 | 418 | |
419 | 419 | return true; |
420 | 420 | } |