Passed
Push — main ( 93e843...2da435 )
by Thierry
04:54
created
jaxon-upload/src/Manager/Validator.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     {
84 84
         $xDefault = $this->xConfigManager->getAppOption('upload.default.' . $sProperty);
85 85
         $aAllowed = $this->xConfigManager->getAppOption('upload.files.' . $sVarName . '.' . $sProperty, $xDefault);
86
-        if(is_array($aAllowed) && !in_array($sValue, $aAllowed))
86
+        if (is_array($aAllowed) && !in_array($sValue, $aAllowed))
87 87
         {
88 88
             $this->sErrorMessage = $this->xTranslator->trans('errors.upload.' . $sField, [$sField => $sValue]);
89 89
             return false;
@@ -104,7 +104,7 @@  discard block
 block discarded – undo
104 104
     {
105 105
         $xDefault = $this->xConfigManager->getAppOption('upload.default.' . $sProperty, 0);
106 106
         $nSize = $this->xConfigManager->getAppOption('upload.files.' . $sVarName . '.' . $sProperty, $xDefault);
107
-        if($nSize > 0 && (
107
+        if ($nSize > 0 && (
108 108
             ($sProperty == 'max-size' && $nFileSize > $nSize) ||
109 109
             ($sProperty == 'min-size' && $nFileSize < $nSize)))
110 110
         {
@@ -126,25 +126,25 @@  discard block
 block discarded – undo
126 126
     {
127 127
         $this->sErrorMessage = '';
128 128
         // Verify the file extension
129
-        if(!$this->validateFileProperty($sVarName, $xFile->type(), 'types', 'type'))
129
+        if (!$this->validateFileProperty($sVarName, $xFile->type(), 'types', 'type'))
130 130
         {
131 131
             return false;
132 132
         }
133 133
 
134 134
         // Verify the file extension
135
-        if(!$this->validateFileProperty($sVarName, $xFile->extension(), 'extensions', 'extension'))
135
+        if (!$this->validateFileProperty($sVarName, $xFile->extension(), 'extensions', 'extension'))
136 136
         {
137 137
             return false;
138 138
         }
139 139
 
140 140
         // Verify the max size
141
-        if(!$this->validateFileSize($sVarName, $xFile->size(), 'max-size'))
141
+        if (!$this->validateFileSize($sVarName, $xFile->size(), 'max-size'))
142 142
         {
143 143
             return false;
144 144
         }
145 145
 
146 146
         // Verify the min size
147
-        if(!$this->validateFileSize($sVarName, $xFile->size(), 'min-size'))
147
+        if (!$this->validateFileSize($sVarName, $xFile->size(), 'min-size'))
148 148
         {
149 149
             return false;
150 150
         }
Please login to merge, or discard this patch.
jaxon-upload/src/Manager/UploadManager.php 1 patch
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -130,13 +130,13 @@  discard block
 block discarded – undo
130 130
         try
131 131
         {
132 132
             $xFilesystem->createDirectory($sUploadDir);
133
-            if(!$xFilesystem->directoryExists($sUploadDir))
133
+            if (!$xFilesystem->directoryExists($sUploadDir))
134 134
             {
135 135
                 throw new RequestException($this->xTranslator->trans('errors.upload.access'));
136 136
             }
137 137
             return $sUploadDir;
138 138
         }
139
-        catch(FilesystemException $e)
139
+        catch (FilesystemException $e)
140 140
         {
141 141
             $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
142 142
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
@@ -152,7 +152,7 @@  discard block
 block discarded – undo
152 152
     public function filesystem(string $sField = ''): Filesystem
153 153
     {
154 154
         $sField = trim($sField);
155
-        if(isset($this->aFilesystems[$sField]))
155
+        if (isset($this->aFilesystems[$sField]))
156 156
         {
157 157
             return $this->aFilesystems[$sField];
158 158
         }
@@ -160,11 +160,11 @@  discard block
 block discarded – undo
160 160
         // Default upload dir
161 161
         $sStorage = $this->xConfigManager->getAppOption('upload.default.storage', 'upload');
162 162
         $sConfigKey = "upload.files.$sField";
163
-        if($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
163
+        if ($sField !== '' && $this->xConfigManager->hasOption($sConfigKey))
164 164
         {
165 165
             $sStorage = $this->xConfigManager->getAppOption("$sConfigKey.storage", $sStorage);
166 166
         }
167
-        if(!is_string($sStorage))
167
+        if (!is_string($sStorage))
168 168
         {
169 169
             throw new RequestException($this->xTranslator->trans('errors.upload.adapter'));
170 170
         }
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
     {
202 202
         // Check the uploaded file validity
203 203
         $nErrorCode = $xHttpFile->getError();
204
-        if($nErrorCode !== UPLOAD_ERR_OK)
204
+        if ($nErrorCode !== UPLOAD_ERR_OK)
205 205
         {
206 206
             $this->xLogger->error('File upload error.', [
207 207
                 'code' => $nErrorCode,
@@ -215,7 +215,7 @@  discard block
 block discarded – undo
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,
221 221
                 $sName, $sField, $this->sUploadFieldId);
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
         // Set the user file data
225 225
         $xFile = File::fromHttpFile($this->filesystem($sField), $xHttpFile, $sUploadDir, $sName);
226 226
         // Verify file validity (format, size)
227
-        if(!$this->xValidator->validateUploadedFile($sField, $xFile))
227
+        if (!$this->xValidator->validateUploadedFile($sField, $xFile))
228 228
         {
229 229
             throw new RequestException($this->xValidator->getErrorMessage());
230 230
         }
@@ -248,16 +248,16 @@  discard block
 block discarded – undo
248 248
 
249 249
         $aUserFiles = [];
250 250
         $aAllFiles = []; // A flat list of all uploaded files
251
-        foreach($aTempFiles as $sField => $aFiles)
251
+        foreach ($aTempFiles as $sField => $aFiles)
252 252
         {
253 253
             $aUserFiles[$sField] = [];
254 254
             // Get the path to the upload dir
255 255
             $sUploadDir = $this->getUploadDir($sField);
256
-            if(!is_array($aFiles))
256
+            if (!is_array($aFiles))
257 257
             {
258 258
                 $aFiles = [$aFiles];
259 259
             }
260
-            foreach($aFiles as $xHttpFile)
260
+            foreach ($aFiles as $xHttpFile)
261 261
             {
262 262
                 $aFile = $this->makeUploadedFile($xHttpFile, $sUploadDir, $sField);
263 263
                 $aUserFiles[$sField][] = $aFile['user'];
@@ -268,14 +268,14 @@  discard block
 block discarded – undo
268 268
         // Copy the uploaded files from the temp dir to the user dir
269 269
         try
270 270
         {
271
-            foreach($aAllFiles as $aFiles)
271
+            foreach ($aAllFiles as $aFiles)
272 272
             {
273 273
                 $sPath = $aFiles['user']->path();
274 274
                 $xContent = $aFiles['temp']->getStream();
275 275
                 $aFiles['user']->filesystem()->write($sPath, $xContent);
276 276
             }
277 277
         }
278
-        catch(FilesystemException $e)
278
+        catch (FilesystemException $e)
279 279
         {
280 280
             $this->xLogger->error('Filesystem error.', ['message' => $e->getMessage()]);
281 281
             throw new RequestException($this->xTranslator->trans('errors.upload.access'));
Please login to merge, or discard this patch.
jaxon-upload/src/register.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -23,13 +23,13 @@  discard block
 block discarded – undo
23 23
 function registerUpload(): void
24 24
 {
25 25
     $jaxon = jaxon();
26
-    if(!$jaxon->getAppOption('upload.enabled'))
26
+    if (!$jaxon->getAppOption('upload.enabled'))
27 27
     {
28 28
         return;
29 29
     }
30 30
 
31 31
     $di = $jaxon->di();
32
-    if($di->h(UploadHandler::class))
32
+    if ($di->h(UploadHandler::class))
33 33
     {
34 34
         return;
35 35
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
         $xUploadHandler = $di->g(UploadHandler::class);
77 77
         // The HTTP request
78 78
         $xRequest = $di->getRequest();
79
-        if($xUploadHandler->canProcessRequest($xRequest))
79
+        if ($xUploadHandler->canProcessRequest($xRequest))
80 80
         {
81 81
             $xUploadHandler->processRequest($xRequest);
82 82
         }
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
 function register()
98 98
 {
99 99
     // Do nothing if running in cli.
100
-    if(php_sapi_name() !== 'cli')
100
+    if (php_sapi_name() !== 'cli')
101 101
     {
102 102
         _register();
103 103
     };
Please login to merge, or discard this patch.