Passed
Push — ft/mediagallery-existing-asset... ( d90314...381209 )
by Philippe
08:44
created
src/Relations/Relation.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
             ->orderBy('sort', 'ASC')
47 47
             ->get();
48 48
 
49
-        return $relations->map(function (Relation $relation) {
49
+        return $relations->map(function(Relation $relation) {
50 50
             $parent = $relation->parent;
51 51
             $parent->relation = $relation;
52 52
             return $parent;
@@ -60,14 +60,14 @@  discard block
 block discarded – undo
60 60
                             ->orderBy('sort', 'ASC')
61 61
                             ->get();
62 62
 
63
-        return $relations->map(function (Relation $relation) use ($parent_type, $parent_id) {
63
+        return $relations->map(function(Relation $relation) use ($parent_type, $parent_id) {
64 64
 
65 65
             // It could be that the child itself is soft-deleted, if this is the case, we will ignore it and move on.
66 66
             if (!$child = $relation->child) {
67 67
                 if (!$relation->child()->withTrashed()->first()) {
68 68
 //                if ((!method_exists($childInstance, 'trashed')) || ! $childInstance->onlyTrashed()->find($relation->child_id)) {
69 69
                     // If we cannot retrieve it then he collection type is possibly off, this is a database inconsistency and should be addressed
70
-                    throw new \DomainException('Corrupt relation reference. Related child ['.$relation->child_type.'@'.$relation->child_id.'] could not be retrieved for parent [' . $parent_type.'@'.$parent_id.']. Make sure the morph key can resolve to a valid class.');
70
+                    throw new \DomainException('Corrupt relation reference. Related child ['.$relation->child_type.'@'.$relation->child_id.'] could not be retrieved for parent ['.$parent_type.'@'.$parent_id.']. Make sure the morph key can resolve to a valid class.');
71 71
                 }
72 72
 
73 73
                 return null;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
         })
80 80
 
81 81
         // In case of soft-deleted entries, this will be null and should be ignored. We make sure that keys are reset in case of removed child
82
-        ->reject(function ($child) {
82
+        ->reject(function($child) {
83 83
             return is_null($child);
84 84
         })
85 85
         ->values();
@@ -96,10 +96,10 @@  discard block
 block discarded – undo
96 96
 
97 97
     public static function deleteRelationsOf($type, $id)
98 98
     {
99
-        $relations = static::where(function ($query) use ($type, $id) {
99
+        $relations = static::where(function($query) use ($type, $id) {
100 100
             return $query->where('parent_type', $type)
101 101
                          ->where('parent_id', $id);
102
-        })->orWhere(function ($query) use ($type, $id) {
102
+        })->orWhere(function($query) use ($type, $id) {
103 103
             return $query->where('child_type', $type)
104 104
                 ->where('child_id', $id);
105 105
         })->get();
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
 
112 112
     public static function deleteAllChildRelationsOf($type, $id)
113 113
     {
114
-        $relations = static::where(function ($query) use ($type, $id) {
114
+        $relations = static::where(function($query) use ($type, $id) {
115 115
             return $query->where('parent_type', $type)
116 116
                 ->where('parent_id', $id);
117 117
         })->get();
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
 
124 124
     public static function deleteAllParentRelationsOf($type, $id)
125 125
     {
126
-        $relations = static::where(function ($query) use ($type, $id) {
126
+        $relations = static::where(function($query) use ($type, $id) {
127 127
             return $query->where('child_type', $type)
128 128
                 ->where('child_id', $id);
129 129
         })->get();
Please login to merge, or discard this patch.
src/Sets/Set.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
         // If no view has been created for this page collection, we try once again to fetch the content value if any. This will silently fail
53 53
         // if no content value is present. We don't consider the 'content' attribute to be a default as we do for module.
54
-        return $this->map(function ($item) {
54
+        return $this->map(function($item) {
55 55
             return ($this->viewParent && $item instanceof ViewableContract)
56 56
                 ? $item->setViewParent($this->viewParent)->renderView()
57 57
                 : ($item->content ?? '');
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
     {
85 85
         $currentPage = $currentPage ?? request()->get('page', 1);
86 86
         $path = request()->path();
87
-        $items = array_slice($this->all(), ($currentPage - 1) * $perPage);
87
+        $items = array_slice($this->all(), ($currentPage-1) * $perPage);
88 88
 
89 89
         return (new \Illuminate\Pagination\Paginator($items, $perPage ?? $this->paginateSetting('perPage', '12'), $currentPage))->setPath($path);
90 90
     }
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     {
102 102
         $currentPage = $currentPage ?? request()->get('page', 1);
103 103
         $path = '/'.request()->path();
104
-        $items = array_slice($this->all(), ($currentPage - 1) * $perPage, $perPage);
104
+        $items = array_slice($this->all(), ($currentPage-1) * $perPage, $perPage);
105 105
 
106 106
         return (new \Illuminate\Pagination\LengthAwarePaginator($items, $this->paginateSetting('total', $this->count()), $perPage ?? $this->paginateSetting('perPage', '12'), $currentPage))->setPath($path);
107 107
     }
Please login to merge, or discard this patch.
src/Sets/SetReference.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
     {
40 40
         // Constraints
41 41
         if (!isset($values['action'])) {
42
-            throw new \InvalidArgumentException('Set reference array is missing required values for the "action" keys. Given: ' . print_r($values, true));
42
+            throw new \InvalidArgumentException('Set reference array is missing required values for the "action" keys. Given: '.print_r($values, true));
43 43
         }
44 44
 
45 45
         return new static(
@@ -54,14 +54,14 @@  discard block
 block discarded – undo
54 54
     {
55 55
         $sets = config('thinktomorrow.chief.sets', []);
56 56
 
57
-        return collect($sets)->map(function ($set, $key) {
57
+        return collect($sets)->map(function($set, $key) {
58 58
             return SetReference::fromArray($key, $set);
59 59
         });
60 60
     }
61 61
 
62 62
     public static function find($key): ?SetReference
63 63
     {
64
-        return static::all()->filter(function ($ref) use ($key) {
64
+        return static::all()->filter(function($ref) use ($key) {
65 65
             return $ref->key() == $key;
66 66
         })->first();
67 67
     }
@@ -78,13 +78,13 @@  discard block
 block discarded – undo
78 78
 
79 79
         $this->validateAction($class, $method);
80 80
 
81
-        $result = call_user_func_array([app($class),$method], $this->parameters($class, $method, $parent));
81
+        $result = call_user_func_array([app($class), $method], $this->parameters($class, $method, $parent));
82 82
 
83
-        if (! $result instanceof Set && $result instanceof Collection) {
83
+        if (!$result instanceof Set && $result instanceof Collection) {
84 84
             return new Set($result->all(), $this->key);
85 85
         }
86 86
 
87
-        if (! $result instanceof Set && $result instanceof Paginator) {
87
+        if (!$result instanceof Set && $result instanceof Paginator) {
88 88
             return new Set($result->all(), $this->key, [
89 89
                 'paginate' => [
90 90
                     'total' => $result->total(),
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
 
153 153
     private static function validateAction($class, $method)
154 154
     {
155
-        if (! class_exists($class)) {
155
+        if (!class_exists($class)) {
156 156
             throw new \InvalidArgumentException('The class ['.$class.'] isn\'t a valid class reference or does not exist in the chief-settings.sets config entry.');
157 157
         }
158 158
 
Please login to merge, or discard this patch.
src/Urls/UrlHelper.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public static function onlineModels(bool $onlySingles = false, Model $ignoredModel = null): Collection
41 41
     {
42
-        $models = chiefMemoize('all-online-models', function () use ($onlySingles) {
42
+        $models = chiefMemoize('all-online-models', function() use ($onlySingles) {
43 43
             $builder = UrlRecord::whereNull('redirect_id')
44 44
                 ->select('model_type', 'model_id')
45 45
                 ->groupBy('model_type', 'model_id');
@@ -48,17 +48,17 @@  discard block
 block discarded – undo
48 48
                 $builder->where('model_type', 'singles');
49 49
             }
50 50
 
51
-            return $builder->get()->mapToGroups(function ($record) {
51
+            return $builder->get()->mapToGroups(function($record) {
52 52
                 return [$record->model_type => $record->model_id];
53
-            })->map(function ($record, $key) {
53
+            })->map(function($record, $key) {
54 54
                 return Morphables::instance($key)->find($record->toArray());
55
-            })->map->reject(function ($model) {
55
+            })->map->reject(function($model) {
56 56
                 return is_null($model) || !$model->isPublished(); // Invalid references to archived or removed models where url record still exists.
57 57
             })->flatten();
58 58
         }, [$onlySingles]);
59 59
 
60 60
         if ($ignoredModel) {
61
-            $models = $models->reject(function ($model) use ($ignoredModel) {
61
+            $models = $models->reject(function($model) use ($ignoredModel) {
62 62
                 return (get_class($model) === get_class($ignoredModel) && $model->id === $ignoredModel->id);
63 63
             });
64 64
         }
Please login to merge, or discard this patch.
src/Media/UploadMedia.php 1 patch
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
         if (isset(json_decode($file)->output)) {
114 114
             $image_name = json_decode($file)->output->name;
115 115
             $asset      = app(AddAsset::class)->add($model, json_decode($file)->output->image, $type, $locale, $this->sluggifyFilename($image_name));
116
-        } else {
116
+        }else {
117 117
             if ($file instanceof UploadedFile) {
118 118
                 $image_name = $file->getClientOriginalName();
119 119
                 $asset      = app(AddAsset::class)->add($model, $file, $type, $locale, $this->sluggifyFilename($image_name));
@@ -121,16 +121,16 @@  discard block
 block discarded – undo
121 121
                 // New files are passed with their filename (instead of their id)
122 122
                 // For new files we will replace the filename with the id.
123 123
                 if (false !== ($key = array_search($image_name, $files_order))) {
124
-                    $files_order[$key] = (string) $asset->id;
124
+                    $files_order[$key] = (string)$asset->id;
125 125
                 }
126
-            }else{
127
-                try{
126
+            }else {
127
+                try {
128 128
                     
129 129
                     $file   = Asset::find($file);
130
-                    if(!$file) return;
130
+                    if (!$file) return;
131 131
 
132 132
                     $asset  = app(AddAsset::class)->add($model, $file, $type, $locale);
133
-                }catch(AssetUploadException $e)
133
+                } catch (AssetUploadException $e)
134 134
                 {
135 135
                 }
136 136
             }
@@ -143,9 +143,9 @@  discard block
 block discarded – undo
143 143
      */
144 144
     private function sluggifyFilename($filename): string
145 145
     {
146
-        $extension = substr($filename, strrpos($filename, '.') + 1);
146
+        $extension = substr($filename, strrpos($filename, '.')+1);
147 147
         $filename  = substr($filename, 0, strrpos($filename, '.'));
148
-        $filename  = Str::slug($filename) . '.' . $extension;
148
+        $filename  = Str::slug($filename).'.'.$extension;
149 149
 
150 150
         return $filename;
151 151
     }
@@ -161,9 +161,9 @@  discard block
 block discarded – undo
161 161
                 if ($file instanceof UploadedFile && !$file->isValid()) {
162 162
                     if ($file->getError() == UPLOAD_ERR_INI_SIZE) {
163 163
                         throw new FileTooBigException(
164
-                            'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. ' .
165
-                            'upload_max_filesize: ' . (int)ini_get('upload_max_filesize') . 'MB, ' .
166
-                            'post_max_size: ' . (int)(ini_get('post_max_size')) . 'MB'
164
+                            'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. '.
165
+                            'upload_max_filesize: '.(int)ini_get('upload_max_filesize').'MB, '.
166
+                            'post_max_size: '.(int)(ini_get('post_max_size')).'MB'
167 167
                         );
168 168
                     }
169 169
                 }
@@ -177,16 +177,16 @@  discard block
 block discarded – undo
177 177
         foreach ($files_by_type as $type => $files) {
178 178
             foreach ($files as $locale => $_files) {
179 179
                 if (!in_array($locale, config('translatable.locales'))) {
180
-                    throw new \InvalidArgumentException('Corrupt file payload. key is expected to be a valid locale [' . implode(',', config('translatable.locales', [])). ']. Instead [' . $locale . '] is given.');
180
+                    throw new \InvalidArgumentException('Corrupt file payload. key is expected to be a valid locale ['.implode(',', config('translatable.locales', [])).']. Instead ['.$locale.'] is given.');
181 181
                 }
182 182
 
183 183
                 if (!is_array($_files)) {
184
-                    throw new \InvalidArgumentException('A valid files entry should be an array of files, key with either [new, replace or delete]. Instead a ' . gettype($_files) . ' is given.');
184
+                    throw new \InvalidArgumentException('A valid files entry should be an array of files, key with either [new, replace or delete]. Instead a '.gettype($_files).' is given.');
185 185
                 }
186 186
 
187 187
                 foreach ($_files as $action => $file) {
188 188
                     if (!in_array($action, $actions)) {
189
-                        throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead ' . $action . ' is given.');
189
+                        throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead '.$action.' is given.');
190 190
                     }
191 191
                 }
192 192
             }
Please login to merge, or discard this patch.