@@ -32,7 +32,7 @@ |
||
32 | 32 | |
33 | 33 | $this->app->bind(AchievementsStorageInterface::class, AchievementsStorage::class); |
34 | 34 | |
35 | - $this->app->singleton(AchievementsManager::class, function () { |
|
35 | + $this->app->singleton(AchievementsManager::class, function() { |
|
36 | 36 | $storage = app(AchievementsStorageInterface::class); |
37 | 37 | |
38 | 38 | return new AchievementsManager($storage); |
@@ -59,14 +59,14 @@ discard block |
||
59 | 59 | $criterias = $this->getCriteriasByType($type); |
60 | 60 | |
61 | 61 | if (!count($criterias)) { |
62 | - return []; |
|
62 | + return [ ]; |
|
63 | 63 | } |
64 | 64 | |
65 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($type) { |
|
65 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($type) { |
|
66 | 66 | $query->where('type', $type); |
67 | 67 | }); |
68 | 68 | |
69 | - return $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
69 | + return $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
70 | 70 | /** @var AchievementCriteriaModel $criteria */ |
71 | 71 | |
72 | 72 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | { |
87 | 87 | $query = $owner->achievementCriterias(); |
88 | 88 | |
89 | - call_user_func_array($callback, [$query]); |
|
89 | + call_user_func_array($callback, [ $query ]); |
|
90 | 90 | |
91 | 91 | return $this->transformOwnerCriteriasToProgress($query->get()); |
92 | 92 | } |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | protected function getCriteriasByType(string $type) |
102 | 102 | { |
103 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($type) { |
|
103 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($type) { |
|
104 | 104 | return $className::where('type', $type)->get(); |
105 | 105 | }); |
106 | 106 | } |
@@ -114,14 +114,14 @@ discard block |
||
114 | 114 | */ |
115 | 115 | protected function transformOwnerCriteriasToProgress(Collection $criterias) |
116 | 116 | { |
117 | - return $criterias->keyBy('id')->map(function ($criteria) { |
|
117 | + return $criterias->keyBy('id')->map(function($criteria) { |
|
118 | 118 | /** @var AchievementCriteriaModel $criteria */ |
119 | 119 | |
120 | 120 | return new AchievementCriteriaProgress( |
121 | 121 | intval($criteria->pivot->value), |
122 | 122 | false, |
123 | 123 | intval($criteria->pivot->completed) === 1, |
124 | - is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [] |
|
124 | + is_string($criteria->pivot->progress_data) ? json_decode($criteria->pivot->progress_data, true) : [ ] |
|
125 | 125 | ); |
126 | 126 | }); |
127 | 127 | } |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | 'achievement_id' => $criteria->achievement_id, |
142 | 142 | 'type' => $criteria->type, |
143 | 143 | 'name' => $criteria->name, |
144 | - 'requirements' => $criteria->requirements ?? [], |
|
144 | + 'requirements' => $criteria->requirements ?? [ ], |
|
145 | 145 | 'max_value' => $criteria->max_value, |
146 | 146 | ]; |
147 | 147 | |
148 | 148 | if (!is_null($progress)) { |
149 | - $data['progress'] = [ |
|
149 | + $data[ 'progress' ] = [ |
|
150 | 150 | 'value' => $progress->value, |
151 | 151 | 'changed' => false, |
152 | 152 | 'completed' => $progress->completed, |
@@ -166,14 +166,14 @@ discard block |
||
166 | 166 | */ |
167 | 167 | public function getAchievementsByCriterias(array $criterias) |
168 | 168 | { |
169 | - $achievementIds = array_map(function (AchievementCriteria $criteria) { |
|
169 | + $achievementIds = array_map(function(AchievementCriteria $criteria) { |
|
170 | 170 | return $criteria->achievementId(); |
171 | 171 | }, $criterias); |
172 | 172 | |
173 | 173 | $achievements = $this->getAchievementsByIds(array_unique($achievementIds)); |
174 | 174 | |
175 | 175 | if (!count($achievements)) { |
176 | - return []; |
|
176 | + return [ ]; |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | return $this->transformAchievements($achievements, $criterias)->toArray(); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | public function getAchievementsByIds(array $achievementIds) |
190 | 190 | { |
191 | - return $this->getModelClass(static::MODEL_ACHIEVEMENT, function (string $className) use ($achievementIds) { |
|
191 | + return $this->getModelClass(static::MODEL_ACHIEVEMENT, function(string $className) use ($achievementIds) { |
|
192 | 192 | return $className::whereIn('id', array_unique($achievementIds))->get(); |
193 | 193 | }); |
194 | 194 | } |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | $achievements->load('criterias'); |
208 | 208 | } |
209 | 209 | |
210 | - return $achievements->map([$this, 'convertAchievementModelWithCriterias'])->toArray(); |
|
210 | + return $achievements->map([ $this, 'convertAchievementModelWithCriterias' ])->toArray(); |
|
211 | 211 | } |
212 | 212 | |
213 | 213 | /** |
@@ -219,7 +219,7 @@ discard block |
||
219 | 219 | */ |
220 | 220 | public function convertAchievementModelWithCriterias($achievement) |
221 | 221 | { |
222 | - $criterias = $achievement->criterias->map(function ($criteria) { |
|
222 | + $criterias = $achievement->criterias->map(function($criteria) { |
|
223 | 223 | /** @var AchievementCriteriaModel $criteria */ |
224 | 224 | |
225 | 225 | return $this->transformCriteriaWithProgress($criteria); |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | protected function transformAchievements(Collection $achievements, array $criterias) |
240 | 240 | { |
241 | - return $achievements->map(function ($achievement) use ($criterias) { |
|
241 | + return $achievements->map(function($achievement) use ($criterias) { |
|
242 | 242 | /** @var AchievementModel $achievement */ |
243 | 243 | |
244 | 244 | return $this->transformSingleAchievement($achievement, $criterias); |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | */ |
256 | 256 | protected function transformSingleAchievement($achievement, array $criterias) |
257 | 257 | { |
258 | - $achievementCriterias = array_filter($criterias, function (AchievementCriteria $criteria) use ($achievement) { |
|
258 | + $achievementCriterias = array_filter($criterias, function(AchievementCriteria $criteria) use ($achievement) { |
|
259 | 259 | return $criteria->achievementId() === $achievement->id; |
260 | 260 | }); |
261 | 261 | |
262 | 262 | // Since we're dealing with owner-related criterias (progress exists if owner has any value), |
263 | 263 | // we can simply count completed criterias & determine if achievement has been completed. |
264 | 264 | $completedCriteriasCount = array_sum( |
265 | - array_map(function (AchievementCriteria $criteria) { |
|
265 | + array_map(function(AchievementCriteria $criteria) { |
|
266 | 266 | return $criteria->completed() ? 1 : 0; |
267 | 267 | }, $achievementCriterias) |
268 | 268 | ); |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | $collection = collect($achievements); |
291 | 291 | |
292 | - $index = $collection->search(function (Achievement $achievement) use ($criteria) { |
|
292 | + $index = $collection->search(function(Achievement $achievement) use ($criteria) { |
|
293 | 293 | return $achievement->id() === $criteria->achievementId(); |
294 | 294 | }); |
295 | 295 | |
@@ -313,14 +313,14 @@ discard block |
||
313 | 313 | $criterias = $this->getCriteriasByAchievementIds($achievementIds); |
314 | 314 | |
315 | 315 | if (!count($criterias)) { |
316 | - return []; |
|
316 | + return [ ]; |
|
317 | 317 | } |
318 | 318 | |
319 | - $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function ($query) use ($criterias) { |
|
319 | + $ownerCriteriaProgress = $this->getOwnerCriteriasProgress($owner, function($query) use ($criterias) { |
|
320 | 320 | $query->whereIn('achievement_criteria_model_id', $criterias->pluck('id')); |
321 | 321 | }); |
322 | 322 | |
323 | - $achievementsCriterias = $criterias->map(function ($criteria) use ($ownerCriteriaProgress) { |
|
323 | + $achievementsCriterias = $criterias->map(function($criteria) use ($ownerCriteriaProgress) { |
|
324 | 324 | /** @var AchievementCriteriaModel $criteria */ |
325 | 325 | |
326 | 326 | return $this->transformCriteriaWithProgress($criteria, $ownerCriteriaProgress->get($criteria->id)); |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | */ |
339 | 339 | public function getCriteriasByAchievementIds(array $achievementIds) |
340 | 340 | { |
341 | - return $this->getModelClass(static::MODEL_CRITERIA, function (string $className) use ($achievementIds) { |
|
341 | + return $this->getModelClass(static::MODEL_CRITERIA, function(string $className) use ($achievementIds) { |
|
342 | 342 | return $className::whereIn('achievement_id', $achievementIds)->get(); |
343 | 343 | }); |
344 | 344 | } |
@@ -379,10 +379,10 @@ discard block |
||
379 | 379 | public function setAchievementsCompleted($owner, array $achievements) |
380 | 380 | { |
381 | 381 | $now = Carbon::now(); |
382 | - $patch = []; |
|
382 | + $patch = [ ]; |
|
383 | 383 | |
384 | 384 | foreach ($achievements as $achievement) { |
385 | - $patch[$achievement->id()] = ['completed_at' => $now]; |
|
385 | + $patch[ $achievement->id() ] = [ 'completed_at' => $now ]; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | $owner->achievements()->syncWithoutDetaching($patch); |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | 'achievementables', |
24 | 24 | null, |
25 | 25 | 'achievement_model_id' |
26 | - )->withPivot(['completed_at']); |
|
26 | + )->withPivot([ 'completed_at' ]); |
|
27 | 27 | } |
28 | 28 | |
29 | 29 | /** |
@@ -49,6 +49,6 @@ discard block |
||
49 | 49 | 'achievement_criteriables', |
50 | 50 | null, |
51 | 51 | 'achievement_criteria_model_id' |
52 | - )->withPivot(['value', 'completed', 'progress_data', 'updated_at']); |
|
52 | + )->withPivot([ 'value', 'completed', 'progress_data', 'updated_at' ]); |
|
53 | 53 | } |
54 | 54 | } |