Passed
Pull Request — 1.1 (#17)
by Quentin
04:56
created
src/Repositories/Behaviors/HandleTranslations.php 1 patch
Spacing   +9 added lines, -9 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,10 +76,10 @@  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
-                        $q->where($attribute, 'like', '%'.$scopes[$attribute].'%');
82
+                        $q->where($attribute, 'like', '%' . $scopes[$attribute] . '%');
83 83
                     }
84 84
                 }
85 85
             });
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
             $isOrdered = false;
105 105
             foreach ($attributes as $attribute) {
106 106
                 if (isset($orders[$attribute])) {
107
-                    $query->orderBy($tableTranslation.'.'.$attribute, $orders[$attribute]);
107
+                    $query->orderBy($tableTranslation . '.' . $attribute, $orders[$attribute]);
108 108
                     $isOrdered = true;
109 109
                     unset($orders[$attribute]);
110 110
                 }
@@ -112,9 +112,9 @@  discard block
 block discarded – undo
112 112
 
113 113
             if ($isOrdered) {
114 114
                 $query
115
-                    ->join($tableTranslation, $foreignKey, '=', $table.'.id')
116
-                    ->where($tableTranslation.'.locale', '=', $orders['locale'] ?? app()->getLocale())
117
-                    ->select($table.'.*');
115
+                    ->join($tableTranslation, $foreignKey, '=', $table . '.id')
116
+                    ->where($tableTranslation . '.locale', '=', $orders['locale'] ?? app()->getLocale())
117
+                    ->select($table . '.*');
118 118
             }
119 119
         }
120 120
     }
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleRepeaters.php 1 patch
Spacing   +5 added lines, -5 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
         }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
             $relationField['position'] = $index + 1;
46 46
             if (isset($relationField['id']) && starts_with($relationField['id'], $relation)) {
47 47
                 // row already exists, let's update
48
-                $id = str_replace($relation.'-', '', $relationField['id']);
48
+                $id = str_replace($relation . '-', '', $relationField['id']);
49 49
                 $relationRepository->update($id, $relationField);
50 50
                 $currentIdList[] = $id;
51 51
             } else {
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 
80 80
         foreach ($object->$relation as $relationItem) {
81 81
             $repeaters[] = [
82
-                'id'    => $relation.'-'.$relationItem->id,
82
+                'id'    => $relation . '-' . $relationItem->id,
83 83
                 'type'  => $repeatersConfig[$relation]['component'],
84 84
                 'title' => $repeatersConfig[$relation]['title'],
85 85
             ];
@@ -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/HandleBlocks.php 1 patch
Spacing   +13 added lines, -13 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);
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 
46 46
         $blockRepository->bulkDelete($object->blocks()->pluck('id')->toArray());
47 47
 
48
-        $this->getBlocks($object, $fields)->each(function ($block) use ($object, $blockRepository) {
48
+        $this->getBlocks($object, $fields)->each(function($block) use ($object, $blockRepository) {
49 49
             $blockCreated = $blockRepository->create($block);
50 50
 
51
-            $block['blocks']->each(function ($childBlock) use ($blockCreated, $blockRepository) {
51
+            $block['blocks']->each(function($childBlock) use ($blockCreated, $blockRepository) {
52 52
                 $childBlock['parent_id'] = $blockCreated->id;
53 53
                 $blockRepository->create($childBlock);
54 54
             });
@@ -127,9 +127,9 @@  discard block
 block discarded – undo
127 127
                     ];
128 128
                 }
129 129
 
130
-                $fields['blocksFields'][] = collect($block['content'])->filter(function ($value, $key) {
130
+                $fields['blocksFields'][] = collect($block['content'])->filter(function($value, $key) {
131 131
                     return $key !== 'browsers';
132
-                })->map(function ($value, $key) use ($block) {
132
+                })->map(function($value, $key) use ($block) {
133 133
                     return [
134 134
                         'name'  => "blocks[$block->id][$key]",
135 135
                         'value' => $value,
@@ -141,7 +141,7 @@  discard block
 block discarded – undo
141 141
                 $medias = $blockFormFields['medias'];
142 142
 
143 143
                 if ($medias) {
144
-                    $fields['blocksMedias'][] = collect($medias)->mapWithKeys(function ($value, $key) use ($block) {
144
+                    $fields['blocksMedias'][] = collect($medias)->mapWithKeys(function($value, $key) use ($block) {
145 145
                         return [
146 146
                             "blocks[$block->id][$key]" => $value,
147 147
                         ];
@@ -151,8 +151,8 @@  discard block
 block discarded – undo
151 151
                 $files = $blockFormFields['files'];
152 152
 
153 153
                 if ($files) {
154
-                    collect($files)->each(function ($rolesWithFiles, $locale) use (&$fields, $block) {
155
-                        $fields['blocksFiles'][] = collect($rolesWithFiles)->mapWithKeys(function ($files, $role) use ($locale, $block) {
154
+                    collect($files)->each(function($rolesWithFiles, $locale) use (&$fields, $block) {
155
+                        $fields['blocksFiles'][] = collect($rolesWithFiles)->mapWithKeys(function($files, $role) use ($locale, $block) {
156 156
                             return [
157 157
                                 "blocks[$block->id][$role][$locale]" => $files,
158 158
                             ];
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
 
188 188
     protected function getBlockBrowsers($block)
189 189
     {
190
-        return collect($block['content']['browsers'])->mapWithKeys(function ($ids, $relation) use ($block) {
190
+        return collect($block['content']['browsers'])->mapWithKeys(function($ids, $relation) use ($block) {
191 191
             $relationRepository = $this->getModelRepository($relation);
192 192
             $relatedItems = $relationRepository->get([], ['id' => $ids], [], -1);
193 193
             $sortedRelatedItems = array_flip($ids);
@@ -196,13 +196,13 @@  discard block
 block discarded – undo
196 196
                 $sortedRelatedItems[$item->id] = $item;
197 197
             }
198 198
 
199
-            $items = collect(array_values($sortedRelatedItems))->filter(function ($value) {
199
+            $items = collect(array_values($sortedRelatedItems))->filter(function($value) {
200 200
                 return is_object($value);
201
-            })->map(function ($relatedElement) use ($relation) {
201
+            })->map(function($relatedElement) use ($relation) {
202 202
                 return [
203 203
                     'id'   => $relatedElement->id,
204 204
                     'name' => $relatedElement->titleInBrowser ?? $relatedElement->title,
205
-                    'edit' => moduleRoute($relation, config('twill.block_editor.browser_route_prefixes.'.$relation), 'edit', $relatedElement->id),
205
+                    'edit' => moduleRoute($relation, config('twill.block_editor.browser_route_prefixes.' . $relation), 'edit', $relatedElement->id),
206 206
                 ] + (classHasTrait($relatedElement, HasMedias::class) ? [
207 207
                     'thumbnail' => $relatedElement->defaultCmsImage(['w' => 100, 'h' => 100]),
208 208
                 ] : []);
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
     }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
                 $locale = $locale ?? config('app.locale');
57 57
                 if (in_array($role, $this->model->filesParams ?? [])
58 58
                     || in_array($role, config('twill.block_editor.files', []))) {
59
-                    collect($filesForRole)->each(function ($file) use (&$files, $role, $locale) {
59
+                    collect($filesForRole)->each(function($file) use (&$files, $role, $locale) {
60 60
                         $files->push([
61 61
                             'id'     => $file['id'],
62 62
                             'role'   => $role,
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
         if ($object->has('files')) {
78 78
             foreach ($object->files->groupBy('pivot.role') as $role => $filesByRole) {
79 79
                 foreach ($filesByRole->groupBy('pivot.locale') as $locale => $filesByLocale) {
80
-                    $fields['files'][$locale][$role] = $filesByRole->map(function ($file) {
80
+                    $fields['files'][$locale][$role] = $filesByRole->map(function($file) {
81 81
                         return $file->toCmsArray();
82 82
                     });
83 83
                 }
Please login to merge, or discard this patch.
src/Repositories/Behaviors/HandleTags.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -40,12 +40,12 @@  discard block
 block discarded – undo
40 40
         $tagQuery = $this->getTagsQuery();
41 41
 
42 42
         if (!empty($query)) {
43
-            $tagQuery->where('slug', 'like', '%'.$query.'%');
43
+            $tagQuery->where('slug', 'like', '%' . $query . '%');
44 44
         }
45 45
 
46 46
         if (!empty($ids)) {
47 47
             foreach ($ids as $id) {
48
-                $tagQuery->whereHas('tagged', function ($query) use ($id) {
48
+                $tagQuery->whereHas('tagged', function($query) use ($id) {
49 49
                     $query->where('taggable_id', $id);
50 50
                 });
51 51
             }
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
 
57 57
     public function getTagsList()
58 58
     {
59
-        return $this->getTagsQuery()->where('count', '>', 0)->select('name', 'id')->get()->map(function ($tag) {
59
+        return $this->getTagsQuery()->where('count', '>', 0)->select('name', 'id')->get()->map(function($tag) {
60 60
             return [
61 61
                 'label' => $tag->name,
62 62
                 'value' => $tag->id,
Please login to merge, or discard this patch.
src/Repositories/SettingRepository.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,16 +13,16 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function byKey($key, $section = null)
15 15
     {
16
-        return $this->model->when($section, function ($query) use ($section) {
16
+        return $this->model->when($section, function($query) use ($section) {
17 17
             $query->where('section', $section);
18 18
         })->where('key', $key)->exists() ? $this->model->where('key', $key)->with('translations')->first()->value : null;
19 19
     }
20 20
 
21 21
     public function getFormFields($section = null)
22 22
     {
23
-        return $this->model->when($section, function ($query) use ($section) {
23
+        return $this->model->when($section, function($query) use ($section) {
24 24
             $query->where('section', $section);
25
-        })->with('translations')->get()->mapWithKeys(function ($setting) {
25
+        })->with('translations')->get()->mapWithKeys(function($setting) {
26 26
             $settingValue = [];
27 27
             foreach ($setting->translations as $translation) {
28 28
                 $settingValue[$translation->locale] = $translation->value;
@@ -40,7 +40,7 @@  discard block
 block discarded – undo
40 40
             foreach (getLocales() as $locale) {
41 41
                 array_set(
42 42
                     $settingsTranslated,
43
-                    $key.'.'.$locale,
43
+                    $key . '.' . $locale,
44 44
                     ['value' => $value[$locale]] + ['active' => true]
45 45
                 );
46 46
             }
Please login to merge, or discard this patch.
src/Repositories/BlockRepository.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -28,16 +28,16 @@
 block discarded – undo
28 28
 
29 29
     public function buildFromCmsArray($block, $repeater = false)
30 30
     {
31
-        $blocksFromConfig = config('twill.block_editor.'.($repeater ? 'repeaters' : 'blocks'));
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/Models/Media.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
 
23 23
     public function getDimensionsAttribute()
24 24
     {
25
-        return $this->width.'x'.$this->height;
25
+        return $this->width . 'x' . $this->height;
26 26
     }
27 27
 
28 28
     public function altTextFrom($filename)
Please login to merge, or discard this patch.
src/Models/Revision.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@
 block discarded – undo
22 22
         // Remember to update this if you had fields to the fillable array here
23 23
         // this is to allow child classes to provide a custom foreign key in fillable
24 24
         if (count($this->fillable) == 2) {
25
-            $this->fillable[] = strtolower(str_replace('Revision', '', get_called_class())).'_id';
25
+            $this->fillable[] = strtolower(str_replace('Revision', '', get_called_class())) . '_id';
26 26
         }
27 27
     }
28 28
 
Please login to merge, or discard this patch.