Passed
Push — main ( e654d0...9e81b9 )
by Thierry
02:07
created
src/Manager/FileStorage.php 1 patch
Spacing   +5 added lines, -6 removed lines patch added patch discarded remove patch
@@ -80,8 +80,7 @@  discard block
 block discarded – undo
80 80
     {
81 81
         // Local file system adapter
82 82
         $this->registerAdapter('local', function(string $sRootDir, $xOptions) {
83
-            return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) :
84
-                new LocalFilesystemAdapter($sRootDir, $xOptions);
83
+            return empty($xOptions) ? new LocalFilesystemAdapter($sRootDir) : new LocalFilesystemAdapter($sRootDir, $xOptions);
85 84
         });
86 85
 
87 86
         // In memory file system adapter
@@ -144,7 +143,7 @@  discard block
 block discarded – undo
144 143
     public function filesystem(string $sField = ''): Filesystem
145 144
     {
146 145
         $sField = trim($sField);
147
-        if(isset($this->aFilesystems[$sField]))
146
+        if (isset($this->aFilesystems[$sField]))
148 147
         {
149 148
             return $this->aFilesystems[$sField];
150 149
         }
@@ -154,18 +153,18 @@  discard block
 block discarded – undo
154 153
         $sRootDir = $this->xConfigManager->getOption('upload.default.dir', '');
155 154
         $aOptions = $this->xConfigManager->getOption('upload.default.options');
156 155
         $sConfigKey = "upload.files.$sField";
157
-        if($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
156
+        if ($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
158 157
         {
159 158
             $sStorage = $this->xConfigManager->getOption("$sConfigKey.storage", $sStorage);
160 159
             $sRootDir = $this->xConfigManager->getOption("$sConfigKey.dir", $sRootDir);
161 160
             $aOptions = $this->xConfigManager->getOption("$sConfigKey.options", $aOptions);
162 161
         }
163 162
 
164
-        if(!is_string($sRootDir))
163
+        if (!is_string($sRootDir))
165 164
         {
166 165
             throw new RequestException($this->xTranslator->trans('errors.upload.dir'));
167 166
         }
168
-        if(!isset($this->aAdapters[$sStorage]))
167
+        if (!isset($this->aAdapters[$sStorage]))
169 168
         {
170 169
             throw new RequestException($this->xTranslator->trans('errors.upload.adapter'));
171 170
         }
Please login to merge, or discard this patch.
src/Manager/UploadManager.php 2 patches
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -153,13 +153,13 @@  discard block
 block discarded – undo
153 153
         try
154 154
         {
155 155
             $xFilesystem->createDirectory($sUploadDir);
156
-            if($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC)
156
+            if ($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC)
157 157
             {
158 158
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
159 159
             }
160 160
             return $sUploadDir;
161 161
         }
162
-        catch(FilesystemException $e)
162
+        catch (FilesystemException $e)
163 163
         {
164 164
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
165 165
         }
@@ -202,20 +202,20 @@  discard block
 block discarded – undo
202 202
     private function makeUploadedFile(string $sUploadDir, string $sField, UploadedFile $xHttpFile): File
203 203
     {
204 204
         // Check the uploaded file validity
205
-        if($xHttpFile->getError())
205
+        if ($xHttpFile->getError())
206 206
         {
207 207
             throw new RequestException($this->xTranslator->trans('errors.upload.failed', ['name' => $sField]));
208 208
         }
209 209
         // Set the user file data
210 210
         $xFile = File::fromHttpFile($this->xFileStorage->filesystem($sField), $sUploadDir, $xHttpFile);
211 211
         // Verify file validity (format, size)
212
-        if(!$this->xValidator->validateUploadedFile($sField, $xFile))
212
+        if (!$this->xValidator->validateUploadedFile($sField, $xFile))
213 213
         {
214 214
             throw new RequestException($this->xValidator->getErrorMessage());
215 215
         }
216 216
         // Filename without the extension. Needs to be sanitized.
217 217
         $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME);
218
-        if($this->cNameSanitizer !== null)
218
+        if ($this->cNameSanitizer !== null)
219 219
         {
220 220
             $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sField, $this->sUploadFieldId);
221 221
         }
@@ -240,16 +240,16 @@  discard block
 block discarded – undo
240 240
 
241 241
         $aUserFiles = [];
242 242
         $this->aAllFiles = []; // A flat list of all uploaded files
243
-        foreach($aTempFiles as $sField => $aFiles)
243
+        foreach ($aTempFiles as $sField => $aFiles)
244 244
         {
245 245
             $aUserFiles[$sField] = [];
246 246
             // Get the path to the upload dir
247 247
             $sUploadDir = $this->getUploadDir($sField);
248
-            if(!is_array($aFiles))
248
+            if (!is_array($aFiles))
249 249
             {
250 250
                 $aFiles = [$aFiles];
251 251
             }
252
-            foreach($aFiles as $xHttpFile)
252
+            foreach ($aFiles as $xHttpFile)
253 253
             {
254 254
                 $aUserFiles[$sField][] = $this->makeUploadedFile($sUploadDir, $sField, $xHttpFile);
255 255
             }
@@ -257,12 +257,12 @@  discard block
 block discarded – undo
257 257
         // Copy the uploaded files from the temp dir to the user dir
258 258
         try
259 259
         {
260
-            foreach($this->aAllFiles as $aFiles)
260
+            foreach ($this->aAllFiles as $aFiles)
261 261
             {
262 262
                 $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream());
263 263
             }
264 264
         }
265
-        catch(FilesystemException $e)
265
+        catch (FilesystemException $e)
266 266
         {
267 267
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
268 268
         }
@@ -281,10 +281,10 @@  discard block
 block discarded – undo
281 281
     {
282 282
         // Convert uploaded file to an array
283 283
         $aFiles = [];
284
-        foreach($aUserFiles as $sField => $aFieldFiles)
284
+        foreach ($aUserFiles as $sField => $aFieldFiles)
285 285
         {
286 286
             $aFiles[$sField] = [];
287
-            foreach($aFieldFiles as $aFieldFile)
287
+            foreach ($aFieldFiles as $aFieldFile)
288 288
             {
289 289
                 $aFiles[$sField][] = $aFieldFile->toTempData();
290 290
             }
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
         {
297 297
             $this->xFileStorage->filesystem()->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles));
298 298
         }
299
-        catch(FilesystemException $e)
299
+        catch (FilesystemException $e)
300 300
         {
301 301
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
302 302
         }
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
     private function getUploadTempFile(string $sTempFile): string
315 315
     {
316 316
         // Verify file name validity
317
-        if(!$this->xValidator->validateTempFileName($sTempFile))
317
+        if (!$this->xValidator->validateTempFileName($sTempFile))
318 318
         {
319 319
             throw new RequestException($this->xTranslator->trans('errors.upload.invalid'));
320 320
         }
@@ -322,13 +322,13 @@  discard block
 block discarded – undo
322 322
         $sUploadTempFile = $sUploadDir . $sTempFile . '.json';
323 323
         try
324 324
         {
325
-            if($this->xFileStorage->filesystem()->visibility($sUploadTempFile) !== Visibility::PUBLIC)
325
+            if ($this->xFileStorage->filesystem()->visibility($sUploadTempFile) !== Visibility::PUBLIC)
326 326
             {
327 327
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
328 328
             }
329 329
             return $sUploadTempFile;
330 330
         }
331
-        catch(FilesystemException $e)
331
+        catch (FilesystemException $e)
332 332
         {
333 333
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
334 334
         }
@@ -351,15 +351,15 @@  discard block
 block discarded – undo
351 351
         {
352 352
             $aFiles = json_decode($xFileSystem->read($sUploadTempFile), true);
353 353
         }
354
-        catch(FilesystemException $e)
354
+        catch (FilesystemException $e)
355 355
         {
356 356
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
357 357
         }
358 358
         $aUserFiles = [];
359
-        foreach($aFiles as $sField => $aFieldFiles)
359
+        foreach ($aFiles as $sField => $aFieldFiles)
360 360
         {
361 361
             $aUserFiles[$sField] = [];
362
-            foreach($aFieldFiles as $aFieldFile)
362
+            foreach ($aFieldFiles as $aFieldFile)
363 363
             {
364 364
                 $aUserFiles[$sField][] = File::fromTempFile($this->xFileStorage->filesystem($sField), $aFieldFile);
365 365
             }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
         {
369 369
             $xFileSystem->delete($sUploadTempFile);
370 370
         }
371
-        catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */}
371
+        catch (FilesystemException $e) {/* Not a big deal if the file cannot be deleted. */}
372 372
         return $aUserFiles;
373 373
     }
374 374
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -158,8 +158,7 @@  discard block
 block discarded – undo
158 158
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
159 159
             }
160 160
             return $sUploadDir;
161
-        }
162
-        catch(FilesystemException $e)
161
+        } catch(FilesystemException $e)
163 162
         {
164 163
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
165 164
         }
@@ -261,8 +260,7 @@  discard block
 block discarded – undo
261 260
             {
262 261
                 $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream());
263 262
             }
264
-        }
265
-        catch(FilesystemException $e)
263
+        } catch(FilesystemException $e)
266 264
         {
267 265
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
268 266
         }
@@ -295,8 +293,7 @@  discard block
 block discarded – undo
295 293
         try
296 294
         {
297 295
             $this->xFileStorage->filesystem()->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles));
298
-        }
299
-        catch(FilesystemException $e)
296
+        } catch(FilesystemException $e)
300 297
         {
301 298
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
302 299
         }
@@ -327,8 +324,7 @@  discard block
 block discarded – undo
327 324
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
328 325
             }
329 326
             return $sUploadTempFile;
330
-        }
331
-        catch(FilesystemException $e)
327
+        } catch(FilesystemException $e)
332 328
         {
333 329
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
334 330
         }
@@ -350,8 +346,7 @@  discard block
 block discarded – undo
350 346
         try
351 347
         {
352 348
             $aFiles = json_decode($xFileSystem->read($sUploadTempFile), true);
353
-        }
354
-        catch(FilesystemException $e)
349
+        } catch(FilesystemException $e)
355 350
         {
356 351
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
357 352
         }
@@ -367,8 +362,7 @@  discard block
 block discarded – undo
367 362
         try
368 363
         {
369 364
             $xFileSystem->delete($sUploadTempFile);
370
-        }
371
-        catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */}
365
+        } catch(FilesystemException $e){/* Not a big deal if the file cannot be deleted. */}
372 366
         return $aUserFiles;
373 367
     }
374 368
 }
Please login to merge, or discard this patch.