Passed
Branch main (fce4cd)
by Thierry
08:09
created
src/UploadHandler.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -135,12 +135,12 @@  discard block
 block discarded – undo
135 135
      */
136 136
     public function canProcessRequest(ServerRequestInterface $xRequest): bool
137 137
     {
138
-        if(count($xRequest->getUploadedFiles()) > 0)
138
+        if (count($xRequest->getUploadedFiles()) > 0)
139 139
         {
140 140
             return true;
141 141
         }
142 142
         $aBody = $xRequest->getParsedBody();
143
-        if(is_array($aBody))
143
+        if (is_array($aBody))
144 144
         {
145 145
             return isset($aBody['jxnupl']);
146 146
         }
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
     private function setTempFile(ServerRequestInterface $xRequest): bool
159 159
     {
160 160
         $aBody = $xRequest->getParsedBody();
161
-        if(is_array($aBody))
161
+        if (is_array($aBody))
162 162
         {
163 163
             $this->sTempFile = trim($aBody['jxnupl'] ?? '');
164 164
             return $this->sTempFile !== '';
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function processRequest(ServerRequestInterface $xRequest): bool
180 180
     {
181
-        if($this->setTempFile($xRequest))
181
+        if ($this->setTempFile($xRequest))
182 182
         {
183 183
             // Ajax request following a normal HTTP upload.
184 184
             // Copy the previously uploaded files' location from the temp file.
@@ -186,7 +186,7 @@  discard block
 block discarded – undo
186 186
             return true;
187 187
         }
188 188
 
189
-        if($this->bIsAjaxRequest)
189
+        if ($this->bIsAjaxRequest)
190 190
         {
191 191
             // Ajax request with upload.
192 192
             // Copy the uploaded files from the HTTP request.
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
             $sTempFile = $this->xUploadManager->saveToTempFile($this->aUserFiles);
204 204
             $this->xResponseManager->append(new UploadResponse($this->xPsr17Factory, $sTempFile));
205 205
         }
206
-        catch(Exception $e)
206
+        catch (Exception $e)
207 207
         {
208 208
             $this->xResponseManager->append(new UploadResponse($this->xPsr17Factory, '', $e->getMessage()));
209 209
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -202,8 +202,7 @@
 block discarded – undo
202 202
             $this->aUserFiles = $this->xUploadManager->readFromHttpData($xRequest);
203 203
             $sTempFile = $this->xUploadManager->saveToTempFile($this->aUserFiles);
204 204
             $this->xResponseManager->append(new UploadResponse($this->xPsr17Factory, $sTempFile));
205
-        }
206
-        catch(Exception $e)
205
+        } catch(Exception $e)
207 206
         {
208 207
             $this->xResponseManager->append(new UploadResponse($this->xPsr17Factory, '', $e->getMessage()));
209 208
         }
Please login to merge, or discard this patch.
src/Manager/Validator.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
     {
98 98
         $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty);
99 99
         $aAllowed = $this->xConfigManager->getOption('upload.files.' . $sName . '.' . $sProperty, $xDefault);
100
-        if(is_array($aAllowed) && !in_array($sValue, $aAllowed))
100
+        if (is_array($aAllowed) && !in_array($sValue, $aAllowed))
101 101
         {
102 102
             $this->sErrorMessage = $this->xTranslator->trans('errors.upload.' . $sField, [$sField => $sValue]);
103 103
             return false;
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
     {
119 119
         $xDefault = $this->xConfigManager->getOption('upload.default.' . $sProperty, 0);
120 120
         $nSize = $this->xConfigManager->getOption('upload.files.' . $sName . '.' . $sProperty, $xDefault);
121
-        if($nSize > 0 && (
121
+        if ($nSize > 0 && (
122 122
             ($sProperty == 'max-size' && $nFileSize > $nSize) ||
123 123
             ($sProperty == 'min-size' && $nFileSize < $nSize)))
124 124
         {
@@ -140,25 +140,25 @@  discard block
 block discarded – undo
140 140
     {
141 141
         $this->sErrorMessage = '';
142 142
         // Verify the file extension
143
-        if(!$this->validateFileProperty($sName, $xFile->type(), 'types', 'type'))
143
+        if (!$this->validateFileProperty($sName, $xFile->type(), 'types', 'type'))
144 144
         {
145 145
             return false;
146 146
         }
147 147
 
148 148
         // Verify the file extension
149
-        if(!$this->validateFileProperty($sName, $xFile->extension(), 'extensions', 'extension'))
149
+        if (!$this->validateFileProperty($sName, $xFile->extension(), 'extensions', 'extension'))
150 150
         {
151 151
             return false;
152 152
         }
153 153
 
154 154
         // Verify the max size
155
-        if(!$this->validateFileSize($sName, $xFile->size(), 'max-size'))
155
+        if (!$this->validateFileSize($sName, $xFile->size(), 'max-size'))
156 156
         {
157 157
             return false;
158 158
         }
159 159
 
160 160
         // Verify the min size
161
-        if(!$this->validateFileSize($sName, $xFile->size(), 'min-size'))
161
+        if (!$this->validateFileSize($sName, $xFile->size(), 'min-size'))
162 162
         {
163 163
             return false;
164 164
         }
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
@@ -157,13 +157,13 @@  discard block
 block discarded – undo
157 157
         try
158 158
         {
159 159
             $xFilesystem->createDirectory($sUploadDir);
160
-            if($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC)
160
+            if ($xFilesystem->visibility($sUploadDir) !== Visibility::PUBLIC)
161 161
             {
162 162
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
163 163
             }
164 164
             return $sUploadDir;
165 165
         }
166
-        catch(FilesystemException $e)
166
+        catch (FilesystemException $e)
167 167
         {
168 168
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
169 169
         }
@@ -210,19 +210,19 @@  discard block
 block discarded – undo
210 210
     {
211 211
         // Filename without the extension. Needs to be sanitized.
212 212
         $sName = pathinfo($xHttpFile->getClientFilename(), PATHINFO_FILENAME);
213
-        if($this->cNameSanitizer !== null)
213
+        if ($this->cNameSanitizer !== null)
214 214
         {
215 215
             $sName = (string)call_user_func($this->cNameSanitizer, $sName, $sVarName, $this->sUploadFieldId);
216 216
         }
217 217
         // Check the uploaded file validity
218
-        if($xHttpFile->getError())
218
+        if ($xHttpFile->getError())
219 219
         {
220 220
             throw new RequestException($this->xTranslator->trans('errors.upload.failed', ['name' => $sVarName]));
221 221
         }
222 222
         // Set the user file data
223 223
         $xFile = File::fromHttpFile($xFilesystem, $sUploadDir, $sName, $xHttpFile);
224 224
         // Verify file validity (format, size)
225
-        if(!$this->xValidator->validateUploadedFile($sVarName, $xFile))
225
+        if (!$this->xValidator->validateUploadedFile($sVarName, $xFile))
226 226
         {
227 227
             throw new RequestException($this->xValidator->getErrorMessage());
228 228
         }
@@ -246,16 +246,16 @@  discard block
 block discarded – undo
246 246
 
247 247
         $aUserFiles = [];
248 248
         $this->aAllFiles = []; // A flat list of all uploaded files
249
-        foreach($aTempFiles as $sVarName => $aFiles)
249
+        foreach ($aTempFiles as $sVarName => $aFiles)
250 250
         {
251 251
             $aUserFiles[$sVarName] = [];
252 252
             // Get the path to the upload dir
253 253
             [$xFilesystem, $sUploadDir] = $this->getUploadDir($sVarName);
254
-            if(!is_array($aFiles))
254
+            if (!is_array($aFiles))
255 255
             {
256 256
                 $aFiles = [$aFiles];
257 257
             }
258
-            foreach($aFiles as $xHttpFile)
258
+            foreach ($aFiles as $xHttpFile)
259 259
             {
260 260
                 $aUserFiles[$sVarName][] = $this->makeUploadedFile($xFilesystem, $sUploadDir, $sVarName, $xHttpFile);
261 261
             }
@@ -263,12 +263,12 @@  discard block
 block discarded – undo
263 263
         // Copy the uploaded files from the temp dir to the user dir
264 264
         try
265 265
         {
266
-            foreach($this->aAllFiles as $aFiles)
266
+            foreach ($this->aAllFiles as $aFiles)
267 267
             {
268 268
                 $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream()->getContents());
269 269
             }
270 270
         }
271
-        catch(FilesystemException $e)
271
+        catch (FilesystemException $e)
272 272
         {
273 273
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
274 274
         }
@@ -287,10 +287,10 @@  discard block
 block discarded – undo
287 287
     {
288 288
         // Convert uploaded file to an array
289 289
         $aFiles = [];
290
-        foreach($aUserFiles as $sVarName => $aVarFiles)
290
+        foreach ($aUserFiles as $sVarName => $aVarFiles)
291 291
         {
292 292
             $aFiles[$sVarName] = [];
293
-            foreach($aVarFiles as $aVarFile)
293
+            foreach ($aVarFiles as $aVarFile)
294 294
             {
295 295
                 $aFiles[$sVarName][] = $aVarFile->toTempData();
296 296
             }
@@ -302,7 +302,7 @@  discard block
 block discarded – undo
302 302
         {
303 303
             $xFilesystem->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles));
304 304
         }
305
-        catch(FilesystemException $e)
305
+        catch (FilesystemException $e)
306 306
         {
307 307
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
308 308
         }
@@ -320,7 +320,7 @@  discard block
 block discarded – undo
320 320
     private function getUploadTempFile(string $sTempFile): array
321 321
     {
322 322
         // Verify file name validity
323
-        if(!$this->xValidator->validateTempFileName($sTempFile))
323
+        if (!$this->xValidator->validateTempFileName($sTempFile))
324 324
         {
325 325
             throw new RequestException($this->xTranslator->trans('errors.upload.invalid'));
326 326
         }
@@ -328,13 +328,13 @@  discard block
 block discarded – undo
328 328
         $sUploadTempFile = $sUploadDir . $sTempFile . '.json';
329 329
         try
330 330
         {
331
-            if($xFilesystem->visibility($sUploadTempFile) !== Visibility::PUBLIC)
331
+            if ($xFilesystem->visibility($sUploadTempFile) !== Visibility::PUBLIC)
332 332
             {
333 333
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
334 334
             }
335 335
             return [$xFilesystem, $sUploadTempFile];
336 336
         }
337
-        catch(FilesystemException $e)
337
+        catch (FilesystemException $e)
338 338
         {
339 339
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
340 340
         }
@@ -356,15 +356,15 @@  discard block
 block discarded – undo
356 356
         {
357 357
             $aFiles = json_decode($xFilesystem->read($sUploadTempFile), true);
358 358
         }
359
-        catch(FilesystemException $e)
359
+        catch (FilesystemException $e)
360 360
         {
361 361
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
362 362
         }
363 363
         $aUserFiles = [];
364
-        foreach($aFiles as $sVarName => $aVarFiles)
364
+        foreach ($aFiles as $sVarName => $aVarFiles)
365 365
         {
366 366
             $aUserFiles[$sVarName] = [];
367
-            foreach($aVarFiles as $aVarFile)
367
+            foreach ($aVarFiles as $aVarFile)
368 368
             {
369 369
                 $aUserFiles[$sVarName][] = File::fromTempFile($xFilesystem, $aVarFile);
370 370
             }
@@ -373,7 +373,7 @@  discard block
 block discarded – undo
373 373
         {
374 374
             $xFilesystem->delete($sUploadTempFile);
375 375
         }
376
-        catch(FilesystemException $e){}
376
+        catch (FilesystemException $e) {}
377 377
         return $aUserFiles;
378 378
     }
379 379
 }
Please login to merge, or discard this patch.
Braces   +6 added lines, -12 removed lines patch added patch discarded remove patch
@@ -162,8 +162,7 @@  discard block
 block discarded – undo
162 162
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
163 163
             }
164 164
             return $sUploadDir;
165
-        }
166
-        catch(FilesystemException $e)
165
+        } catch(FilesystemException $e)
167 166
         {
168 167
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
169 168
         }
@@ -267,8 +266,7 @@  discard block
 block discarded – undo
267 266
             {
268 267
                 $aFiles['user']->filesystem()->write($aFiles['user']->path(), $aFiles['temp']->getStream()->getContents());
269 268
             }
270
-        }
271
-        catch(FilesystemException $e)
269
+        } catch(FilesystemException $e)
272 270
         {
273 271
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
274 272
         }
@@ -301,8 +299,7 @@  discard block
 block discarded – undo
301 299
         try
302 300
         {
303 301
             $xFilesystem->write($sUploadDir . $sTempFile . '.json', json_encode($aFiles));
304
-        }
305
-        catch(FilesystemException $e)
302
+        } catch(FilesystemException $e)
306 303
         {
307 304
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
308 305
         }
@@ -333,8 +330,7 @@  discard block
 block discarded – undo
333 330
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
334 331
             }
335 332
             return [$xFilesystem, $sUploadTempFile];
336
-        }
337
-        catch(FilesystemException $e)
333
+        } catch(FilesystemException $e)
338 334
         {
339 335
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
340 336
         }
@@ -355,8 +351,7 @@  discard block
 block discarded – undo
355 351
         try
356 352
         {
357 353
             $aFiles = json_decode($xFilesystem->read($sUploadTempFile), true);
358
-        }
359
-        catch(FilesystemException $e)
354
+        } catch(FilesystemException $e)
360 355
         {
361 356
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
362 357
         }
@@ -372,8 +367,7 @@  discard block
 block discarded – undo
372 367
         try
373 368
         {
374 369
             $xFilesystem->delete($sUploadTempFile);
375
-        }
376
-        catch(FilesystemException $e){}
370
+        } catch(FilesystemException $e){}
377 371
         return $aUserFiles;
378 372
     }
379 373
 }
Please login to merge, or discard this patch.
src/Manager/FileStorage.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -57,11 +57,11 @@
 block discarded – undo
57 57
     {
58 58
         // Default upload dir
59 59
         $sRootDir = $this->xConfigManager->getOption('upload.default.dir');
60
-        if(($sFieldId = trim($sFieldId)) !== '')
60
+        if (($sFieldId = trim($sFieldId)) !== '')
61 61
         {
62 62
             $sRootDir = $this->xConfigManager->getOption('upload.files.' . $sFieldId . '.dir', $sRootDir);
63 63
         }
64
-        if(!is_string($sRootDir))
64
+        if (!is_string($sRootDir))
65 65
         {
66 66
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
67 67
         }
Please login to merge, or discard this patch.
src/UploadResponse.php 1 patch
Spacing   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -99,8 +99,7 @@
 block discarded – undo
99 99
     public function getOutput(): string
100 100
     {
101 101
         $sResult = json_encode(($this->sUploadedFile) ?
102
-            ['code' => 'success', 'upl' => $this->sUploadedFile] :
103
-            ['code' => 'error', 'msg' => $this->sErrorMessage]) . ';';
102
+            ['code' => 'success', 'upl' => $this->sUploadedFile] : ['code' => 'error', 'msg' => $this->sErrorMessage]) . ';';
104 103
         $sConsoleLog = array_reduce($this->aDebugMessages, function($sJsLog, $sMessage) {
105 104
             return "$sJsLog\n\t" . 'console.log("' . addslashes($sMessage) . '");';
106 105
         }, '');
Please login to merge, or discard this patch.
src/start.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
  */
28 28
 function register(Container $di, bool $bForce = false)
29 29
 {
30
-    if(!$bForce && $di->h(UploadHandler::class))
30
+    if (!$bForce && $di->h(UploadHandler::class))
31 31
     {
32 32
         return;
33 33
     }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         {
81 81
             public function onChanges(Config $xConfig)
82 82
             {
83
-                if($xConfig->getOption('core.upload.enabled'))
83
+                if ($xConfig->getOption('core.upload.enabled'))
84 84
                 {
85 85
                     register(jaxon()->di());
86 86
                 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
 
89 89
             public function onChange(Config $xConfig, string $sName)
90 90
             {
91
-                if($sName === 'core.upload.enabled' && $xConfig->getOption('core.upload.enabled'))
91
+                if ($sName === 'core.upload.enabled' && $xConfig->getOption('core.upload.enabled'))
92 92
                 {
93 93
                     register(jaxon()->di());
94 94
                 }
Please login to merge, or discard this patch.