Test Failed
Push — fix/media-validation ( 3351fe )
by Ben
09:34
created
src/Media/Application/FileFieldHandler.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -15,8 +15,8 @@  discard block
 block discarded – undo
15 15
         // Parse request ...
16 16
         $mediaRequest = $this->mediaRequest($field, $request);
17 17
 trap($mediaRequest);
18
-        foreach([MediaRequest::NEW, MediaRequest::REPLACE, MediaRequest::DETACH] as $action) {
19
-            foreach($mediaRequest->getByKey($action) as $input) {
18
+        foreach ([MediaRequest::NEW, MediaRequest::REPLACE, MediaRequest::DETACH] as $action) {
19
+            foreach ($mediaRequest->getByKey($action) as $input) {
20 20
                 $this->$action($model, $input);
21 21
             }
22 22
         }
@@ -29,10 +29,10 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $mediaRequest = new MediaRequest();
31 31
 
32
-        foreach($request->file('files.'.$field->getName(), []) as $locale => $filesPerLocale) {
32
+        foreach ($request->file('files.'.$field->getName(), []) as $locale => $filesPerLocale) {
33 33
 
34
-            foreach($filesPerLocale as $action => $files) {
35
-                foreach($files as $k => $file) {
34
+            foreach ($filesPerLocale as $action => $files) {
35
+                foreach ($files as $k => $file) {
36 36
                     $mediaRequest->add($action, new MediaRequestInput(
37 37
                         $file, $locale, $field->getKey(), ['index' => $k] // index key is used for replace method to indicate the current asset id
38 38
                     ));
Please login to merge, or discard this patch.
src/Media/UploadMedia.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
         if (is_string($file) && isset(json_decode($file)->output)) {
113 113
             $image_name = json_decode($file)->output->name;
114 114
             $asset = app(AddAsset::class)->add($model, json_decode($file)->output->image, $type, $locale, $this->sluggifyFilename($image_name));
115
-        } else {
115
+        }else {
116 116
             if ($file instanceof UploadedFile) {
117 117
                 $image_name = $file->getClientOriginalName();
118 118
 
@@ -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
-                $file   = Asset::find($file);
126
+            }else {
127
+                $file = Asset::find($file);
128 128
                 if ($file) {
129 129
                     if ($model->assetRelation()->where('asset_pivots.type', $type)->where('asset_pivots.locale', $locale)->get()->contains($file)) {
130 130
                         throw new DuplicateAssetException();
131 131
                     }
132 132
 
133
-                    $asset  = app(AddAsset::class)->add($model, $file, $type, $locale);
133
+                    $asset = app(AddAsset::class)->add($model, $file, $type, $locale);
134 134
                 }
135 135
             }
136 136
         }
@@ -142,9 +142,9 @@  discard block
 block discarded – undo
142 142
      */
143 143
     private function sluggifyFilename($filename): string
144 144
     {
145
-        $extension = substr($filename, strrpos($filename, '.') + 1);
145
+        $extension = substr($filename, strrpos($filename, '.')+1);
146 146
         $filename  = substr($filename, 0, strrpos($filename, '.'));
147
-        $filename  = Str::slug($filename) . '.' . $extension;
147
+        $filename  = Str::slug($filename).'.'.$extension;
148 148
 
149 149
         return $filename;
150 150
     }
@@ -160,9 +160,9 @@  discard block
 block discarded – undo
160 160
                 if ($file instanceof UploadedFile && !$file->isValid()) {
161 161
                     if ($file->getError() == UPLOAD_ERR_INI_SIZE) {
162 162
                         throw new FileTooBigException(
163
-                            'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. ' .
164
-                            'upload_max_filesize: ' . (int)ini_get('upload_max_filesize') . 'MB, ' .
165
-                            'post_max_size: ' . (int)(ini_get('post_max_size')) . 'MB'
163
+                            'Cannot upload file because it exceeded the allowed upload_max_filesize: upload_max_filesize is smaller than post size. '.
164
+                            'upload_max_filesize: '.(int)ini_get('upload_max_filesize').'MB, '.
165
+                            'post_max_size: '.(int)(ini_get('post_max_size')).'MB'
166 166
                         );
167 167
                     }
168 168
                 }
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
             foreach ($files as $locale => $_files) {
178 178
                 foreach ($_files as $action => $file) {
179 179
                     if (!in_array($action, $actions)) {
180
-                        throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead ' . $action . ' is given.');
180
+                        throw new \InvalidArgumentException('A valid files entry should have a key of either ['.implode(',', $actions).']. Instead '.$action.' is given.');
181 181
                     }
182 182
                 }
183 183
             }
Please login to merge, or discard this patch.