Completed
Push — 1.1 ( 4d5846...b85b4d )
by Quentin
12s
created
src/Repositories/Behaviors/HandleTags.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
 
47 47
         if (!empty($ids)) {
48 48
             foreach ($ids as $id) {
49
-                $tagQuery->whereHas('tagged', function ($query) use ($id) {
49
+                $tagQuery->whereHas('tagged', function($query) use ($id) {
50 50
                     $query->where('taggable_id', $id);
51 51
                 });
52 52
             }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 
58 58
     public function getTagsList()
59 59
     {
60
-        return $this->getTagsQuery()->where('count', '>', 0)->select('name', 'id')->get()->map(function ($tag) {
60
+        return $this->getTagsQuery()->where('count', '>', 0)->select('name', 'id')->get()->map(function($tag) {
61 61
             return [
62 62
                 'label' => $tag->name,
63 63
                 'value' => $tag->id,
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleTranslations.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -20,12 +20,12 @@  discard block
 block discarded – undo
20 20
 
21 21
             $submittedLanguages = collect($fields['languages'] ?? []);
22 22
 
23
-            $atLeastOneLanguageIsPublished = $submittedLanguages->contains(function ($language) {
23
+            $atLeastOneLanguageIsPublished = $submittedLanguages->contains(function($language) {
24 24
                 return $language['published'];
25 25
             });
26 26
 
27 27
             foreach ($locales as $index => $locale) {
28
-                $submittedLanguage = array_first($submittedLanguages->filter(function ($lang) use ($locale) {
28
+                $submittedLanguage = array_first($submittedLanguages->filter(function($lang) use ($locale) {
29 29
                     return $lang['value'] == $locale;
30 30
                 }));
31 31
 
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
                 $fields[$locale] = [
37 37
                     'active' => $activeField,
38
-                ] + $attributes->mapWithKeys(function ($attribute) use (&$fields, $locale, $localesCount, $index) {
38
+                ] + $attributes->mapWithKeys(function($attribute) use (&$fields, $locale, $localesCount, $index) {
39 39
                     $attributeValue = $fields[$attribute] ?? null;
40 40
 
41 41
                     // if we are at the last locale,
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     {
77 77
         if (property_exists($this->model, 'translatedAttributes')) {
78 78
             $attributes = $this->model->translatedAttributes;
79
-            $query->whereHas('translations', function ($q) use ($scopes, $attributes) {
79
+            $query->whereHas('translations', function($q) use ($scopes, $attributes) {
80 80
                 foreach ($attributes as $attribute) {
81 81
                     if (isset($scopes[$attribute]) && is_string($scopes[$attribute])) {
82 82
                         $q->where($attribute, 'like', '%' . $scopes[$attribute] . '%');
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleRepeaters.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
         $relationRepository = $this->getModelRepository($relation, $model);
13 13
 
14 14
         if (!$keepExisting) {
15
-            $object->$relation()->each(function ($repeaterElement) {
15
+            $object->$relation()->each(function($repeaterElement) {
16 16
                 $repeaterElement->forceDelete();
17 17
             });
18 18
         }
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
             if (isset($relatedItemFormFields['files'])) {
108 108
                 $repeatersFiles = [];
109 109
 
110
-                collect($relatedItemFormFields['files'])->each(function ($rolesWithFiles, $locale) use (&$repeatersFiles, $relation, $relationItem) {
111
-                    $repeatersFiles[] = collect($rolesWithFiles)->mapWithKeys(function ($files, $role) use ($locale, $relation, $relationItem) {
110
+                collect($relatedItemFormFields['files'])->each(function($rolesWithFiles, $locale) use (&$repeatersFiles, $relation, $relationItem) {
111
+                    $repeatersFiles[] = collect($rolesWithFiles)->mapWithKeys(function($files, $role) use ($locale, $relation, $relationItem) {
112 112
                         return [
113 113
                             "blocks[$relation-$relationItem->id][$role][$locale]" => $files,
114 114
                         ];
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleFiles.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
         $filesCollection = collect();
16 16
         $filesFromFields = $this->getFiles($fields);
17 17
 
18
-        $filesFromFields->each(function ($file) use ($object, $filesCollection) {
18
+        $filesFromFields->each(function($file) use ($object, $filesCollection) {
19 19
             $newFile = File::withTrashed()->find($file['id']);
20 20
             $pivot = $newFile->newPivot($object, array_except($file, ['id']), 'fileables', true);
21 21
             $newFile->setRelation('pivot', $pivot);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
         $object->files()->sync([]);
37 37
 
38
-        $this->getFiles($fields)->each(function ($file) use ($object) {
38
+        $this->getFiles($fields)->each(function($file) use ($object) {
39 39
             $object->files()->attach($file['id'], array_except($file, ['id']));
40 40
         });
41 41
     }
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
                 if (in_array($role, $this->model->filesParams ?? [])
58 58
                     || in_array($role, config('twill.block_editor.files', []))) {
59 59
 
60
-                    collect($filesForRole)->each(function ($file) use (&$files, $role, $locale) {
60
+                    collect($filesForRole)->each(function($file) use (&$files, $role, $locale) {
61 61
                         $files->push([
62 62
                             'id' => $file['id'],
63 63
                             'role' => $role,
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
         if ($object->has('files')) {
79 79
             foreach ($object->files->groupBy('pivot.role') as $role => $filesByRole) {
80 80
                 foreach ($filesByRole->groupBy('pivot.locale') as $locale => $filesByLocale) {
81
-                    $fields['files'][$locale][$role] = $filesByRole->map(function ($file) {
81
+                    $fields['files'][$locale][$role] = $filesByRole->map(function($file) {
82 82
                         return $file->toCmsArray();
83 83
                     });
84 84
                 }
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleMedias.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -15,7 +15,7 @@  discard block
 block discarded – undo
15 15
         $mediasCollection = collect();
16 16
         $mediasFromFields = $this->getMedias($fields);
17 17
 
18
-        $mediasFromFields->each(function ($media) use ($object, $mediasCollection) {
18
+        $mediasFromFields->each(function($media) use ($object, $mediasCollection) {
19 19
             $newMedia = Media::withTrashed()->find(is_array($media['id']) ? array_first($media['id']) : $media['id']);
20 20
             $pivot = $newMedia->newPivot($object, array_except($media, ['id']), 'mediables', true);
21 21
             $newMedia->setRelation('pivot', $pivot);
@@ -35,7 +35,7 @@  discard block
 block discarded – undo
35 35
 
36 36
         $object->medias()->sync([]);
37 37
 
38
-        $this->getMedias($fields)->each(function ($media) use ($object) {
38
+        $this->getMedias($fields)->each(function($media) use ($object) {
39 39
             $object->medias()->attach($media['id'], array_except($media, ['id']));
40 40
         });
41 41
     }
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             foreach ($fields['medias'] as $role => $mediasForRole) {
49 49
                 if (in_array($role, array_keys($this->model->mediasParams ?? []))
50 50
                     || in_array($role, array_keys(config('twill.block_editor.crops')))) {
51
-                    collect($mediasForRole)->each(function ($media) use (&$medias, $role) {
51
+                    collect($mediasForRole)->each(function($media) use (&$medias, $role) {
52 52
                         $customMetadatas = $media['metadatas']['custom'] ?? [];
53 53
                         if (isset($media['crops'])) {
54 54
                             foreach ($media['crops'] as $cropName => $cropData) {
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleBlocks.php 1 patch
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -17,13 +17,13 @@  discard block
 block discarded – undo
17 17
         $blocksFromFields = $this->getBlocks($object, $fields);
18 18
         $blockRepository = app(BlockRepository::class);
19 19
 
20
-        $blocksFromFields->each(function ($block, $key) use ($blocksCollection, $blockRepository) {
20
+        $blocksFromFields->each(function($block, $key) use ($blocksCollection, $blockRepository) {
21 21
             $newBlock = $blockRepository->createForPreview($block);
22 22
             $newBlock->id = $key + 1;
23 23
 
24 24
             $blocksCollection->push($newBlock);
25 25
 
26
-            $block['blocks']->each(function ($childBlock) use ($newBlock, $blocksCollection, $blockRepository) {
26
+            $block['blocks']->each(function($childBlock) use ($newBlock, $blocksCollection, $blockRepository) {
27 27
                 $childBlock['parent_id'] = $newBlock->id;
28 28
                 $newChildBlock = $blockRepository->createForPreview($childBlock);
29 29
                 $blocksCollection->push($newChildBlock);
@@ -47,11 +47,11 @@  discard block
 block discarded – undo
47 47
 
48 48
         $blockRepository->bulkDelete($object->blocks()->pluck('id')->toArray());
49 49
 
50
-        $this->getBlocks($object, $fields)->each(function ($block) use ($object, $blockRepository) {
50
+        $this->getBlocks($object, $fields)->each(function($block) use ($object, $blockRepository) {
51 51
 
52 52
             $blockCreated = $blockRepository->create($block);
53 53
 
54
-            $block['blocks']->each(function ($childBlock) use ($blockCreated, $blockRepository) {
54
+            $block['blocks']->each(function($childBlock) use ($blockCreated, $blockRepository) {
55 55
                 $childBlock['parent_id'] = $blockCreated->id;
56 56
                 $blockRepository->create($childBlock);
57 57
             });
@@ -132,9 +132,9 @@  discard block
 block discarded – undo
132 132
                     ];
133 133
                 }
134 134
 
135
-                $fields['blocksFields'][] = collect($block['content'])->filter(function ($value, $key) {
135
+                $fields['blocksFields'][] = collect($block['content'])->filter(function($value, $key) {
136 136
                     return $key !== "browsers";
137
-                })->map(function ($value, $key) use ($block) {
137
+                })->map(function($value, $key) use ($block) {
138 138
                     return [
139 139
                         'name' => "blocks[$block->id][$key]",
140 140
                         'value' => $value,
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
                 $medias = $blockFormFields['medias'];
147 147
 
148 148
                 if ($medias) {
149
-                    $fields['blocksMedias'][] = collect($medias)->mapWithKeys(function ($value, $key) use ($block) {
149
+                    $fields['blocksMedias'][] = collect($medias)->mapWithKeys(function($value, $key) use ($block) {
150 150
                         return [
151 151
                             "blocks[$block->id][$key]" => $value,
152 152
                         ];
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
                 $files = $blockFormFields['files'];
157 157
 
158 158
                 if ($files) {
159
-                    collect($files)->each(function ($rolesWithFiles, $locale) use (&$fields, $block) {
160
-                        $fields['blocksFiles'][] = collect($rolesWithFiles)->mapWithKeys(function ($files, $role) use ($locale, $block) {
159
+                    collect($files)->each(function($rolesWithFiles, $locale) use (&$fields, $block) {
160
+                        $fields['blocksFiles'][] = collect($rolesWithFiles)->mapWithKeys(function($files, $role) use ($locale, $block) {
161 161
                             return [
162 162
                                 "blocks[$block->id][$role][$locale]" => $files,
163 163
                             ];
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 
193 193
     protected function getBlockBrowsers($block)
194 194
     {
195
-        return collect($block['content']['browsers'])->mapWithKeys(function ($ids, $relation) use ($block) {
195
+        return collect($block['content']['browsers'])->mapWithKeys(function($ids, $relation) use ($block) {
196 196
             $relationRepository = $this->getModelRepository($relation);
197 197
             $relatedItems = $relationRepository->get([], ['id' => $ids], [], -1);
198 198
             $sortedRelatedItems = array_flip($ids);
@@ -201,9 +201,9 @@  discard block
 block discarded – undo
201 201
                 $sortedRelatedItems[$item->id] = $item;
202 202
             }
203 203
 
204
-            $items = collect(array_values($sortedRelatedItems))->filter(function ($value) {
204
+            $items = collect(array_values($sortedRelatedItems))->filter(function($value) {
205 205
                 return is_object($value);
206
-            })->map(function ($relatedElement) use ($relation) {
206
+            })->map(function($relatedElement) use ($relation) {
207 207
                 return [
208 208
                     'id' => $relatedElement->id,
209 209
                     'name' => $relatedElement->titleInBrowser ?? $relatedElement->title,
Please login to merge, or discard this patch.
src/Repositories/ModuleRepository.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
     public function create($fields)
118 118
     {
119
-        return DB::transaction(function () use ($fields) {
119
+        return DB::transaction(function() use ($fields) {
120 120
             $original_fields = $fields;
121 121
 
122 122
             $fields = $this->prepareFieldsBeforeCreate($fields);
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
     public function update($id, $fields)
148 148
     {
149
-        DB::transaction(function () use ($id, $fields) {
149
+        DB::transaction(function() use ($id, $fields) {
150 150
             $object = $this->model->findOrFail($id);
151 151
 
152 152
             $this->beforeSave($object, $fields);
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
 
164 164
     public function updateBasic($id, $values, $scopes = [])
165 165
     {
166
-        return DB::transaction(function () use ($id, $values, $scopes) {
166
+        return DB::transaction(function() use ($id, $values, $scopes) {
167 167
             // apply scopes if no id provided
168 168
             if (is_null($id)) {
169 169
                 $query = $this->model->query();
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
 
175 175
                 $query->update($values);
176 176
 
177
-                $query->get()->each(function ($object) use ($values) {
177
+                $query->get()->each(function($object) use ($values) {
178 178
                     $this->afterUpdateBasic($object, $values);
179 179
                 });
180 180
 
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
                 $query = $this->model->whereIn('id', $id);
187 187
                 $query->update($values);
188 188
 
189
-                $query->get()->each(function ($object) use ($values) {
189
+                $query->get()->each(function($object) use ($values) {
190 190
                     $this->afterUpdateBasic($object, $values);
191 191
                 });
192 192
 
@@ -205,14 +205,14 @@  discard block
 block discarded – undo
205 205
 
206 206
     public function setNewOrder($ids)
207 207
     {
208
-        DB::transaction(function () use ($ids) {
208
+        DB::transaction(function() use ($ids) {
209 209
             $this->model->setNewOrder($ids);
210 210
         }, 3);
211 211
     }
212 212
 
213 213
     public function delete($id)
214 214
     {
215
-        return DB::transaction(function () use ($id) {
215
+        return DB::transaction(function() use ($id) {
216 216
             if (($object = $this->model->find($id)) != null) {
217 217
                 $object->delete();
218 218
                 $this->afterDelete($object);
@@ -225,14 +225,14 @@  discard block
 block discarded – undo
225 225
 
226 226
     public function bulkDelete($ids)
227 227
     {
228
-        return DB::transaction(function () use ($ids) {
228
+        return DB::transaction(function() use ($ids) {
229 229
             try {
230 230
                 $query = $this->model->whereIn('id', $ids);
231 231
                 $objects = $query->get();
232 232
 
233 233
                 $query->delete();
234 234
 
235
-                $objects->each(function ($object) {
235
+                $objects->each(function($object) {
236 236
                     $this->afterDelete($object);
237 237
                 });
238 238
             } catch (\Exception $e) {
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
     public function restore($id)
248 248
     {
249
-        return DB::transaction(function () use ($id) {
249
+        return DB::transaction(function() use ($id) {
250 250
             if (($object = $this->model->withTrashed()->find($id)) != null) {
251 251
                 $object->restore();
252 252
                 $this->afterRestore($object);
@@ -259,14 +259,14 @@  discard block
 block discarded – undo
259 259
 
260 260
     public function bulkRestore($ids)
261 261
     {
262
-        return DB::transaction(function () use ($ids) {
262
+        return DB::transaction(function() use ($ids) {
263 263
             try {
264 264
                 $query = $this->model->withTrashed()->whereIn('id', $ids);
265 265
                 $objects = $query->get();
266 266
 
267 267
                 $query->restore();
268 268
 
269
-                $objects->each(function ($object) {
269
+                $objects->each(function($object) {
270 270
                     $this->afterRestore($object);
271 271
                 });
272 272
             } catch (\Exception $e) {
@@ -462,7 +462,7 @@  discard block
 block discarded – undo
462 462
 
463 463
     public function getFormFieldsForBrowser($object, $relation, $routePrefix = null, $titleKey = 'title', $moduleName = null)
464 464
     {
465
-        return $object->$relation->map(function ($relatedElement) use ($titleKey, $routePrefix, $relation, $moduleName) {
465
+        return $object->$relation->map(function($relatedElement) use ($titleKey, $routePrefix, $relation, $moduleName) {
466 466
             return [
467 467
                 'id' => $relatedElement->id,
468 468
                 'name' => $relatedElement->titleInBrowser ?? $relatedElement->$titleKey,
@@ -517,7 +517,7 @@  discard block
 block discarded – undo
517 517
     {
518 518
         if (isset($scopes[$scopeField])) {
519 519
             $id = $scopes[$scopeField];
520
-            $query->whereHas($scopeRelation, function ($query) use ($id, $scopeField) {
520
+            $query->whereHas($scopeRelation, function($query) use ($id, $scopeField) {
521 521
                 $query->where($scopeField, $id);
522 522
             });
523 523
             unset($scopes[$scopeField]);
@@ -536,7 +536,7 @@  discard block
 block discarded – undo
536 536
     {
537 537
 
538 538
         if (isset($scopes[$scopeField]) && is_string($scopes[$scopeField])) {
539
-            $query->where(function ($query) use (&$scopes, $scopeField, $orFields) {
539
+            $query->where(function($query) use (&$scopes, $scopeField, $orFields) {
540 540
                 foreach ($orFields as $field) {
541 541
                     $query->orWhere($field, $this->getLikeOperator(), '%' . $scopes[$scopeField] . '%');
542 542
                     unset($scopes[$field]);
Please login to merge, or discard this patch.
src/Repositories/BlockRepository.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,14 +30,14 @@
 block discarded – undo
30 30
     {
31 31
         $blocksFromConfig = config('twill.block_editor.' . ($repeater ? 'repeaters' : 'blocks'));
32 32
 
33
-        $block['type'] = collect($blocksFromConfig)->search(function ($blockConfig) use ($block) {
33
+        $block['type'] = collect($blocksFromConfig)->search(function($blockConfig) use ($block) {
34 34
             return $blockConfig['component'] === $block['type'];
35 35
         });
36 36
 
37 37
         $block['content'] = empty($block['content']) ? new \stdClass : (object) $block['content'];
38 38
 
39 39
         if ($block['browsers']) {
40
-            $browsers = collect($block['browsers'])->map(function ($items) {
40
+            $browsers = collect($block['browsers'])->map(function($items) {
41 41
                 return collect($items)->pluck('id');
42 42
             })->toArray();
43 43
 
Please login to merge, or discard this patch.
src/Repositories/SettingRepository.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -14,16 +14,16 @@
 block discarded – undo
14 14
 
15 15
     public function byKey($key, $section = null)
16 16
     {
17
-        return $this->model->when($section, function ($query) use ($section) {
17
+        return $this->model->when($section, function($query) use ($section) {
18 18
             $query->where('section', $section);
19 19
         })->where('key', $key)->exists() ? $this->model->where('key', $key)->with('translations')->first()->value : null;
20 20
     }
21 21
 
22 22
     public function getFormFields($section = null)
23 23
     {
24
-        return $this->model->when($section, function ($query) use ($section) {
24
+        return $this->model->when($section, function($query) use ($section) {
25 25
             $query->where('section', $section);
26
-        })->with('translations')->get()->mapWithKeys(function ($setting) {
26
+        })->with('translations')->get()->mapWithKeys(function($setting) {
27 27
             $settingValue = [];
28 28
             foreach ($setting->translations as $translation) {
29 29
                 $settingValue[$translation->locale] = $translation->value;
Please login to merge, or discard this patch.