Passed
Push — develop ( f4f7a3...812ad5 )
by Nikolay
15:03 queued 12s
created
src/PBXCoreREST/Lib/FilesManagementProcessor.php 1 patch
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -90,18 +90,18 @@  discard block
 block discarded – undo
90 90
         }
91 91
         $parameters['uploadDir'] = $di->getShared('config')->path('www.uploadDir');
92 92
         $parameters['tempDir']   = "{$parameters['uploadDir']}/{$parameters['resumableIdentifier']}";
93
-        if ( ! Util::mwMkdir($parameters['tempDir'])) {
94
-            $res->messages[] = 'Temp dir does not exist ' . $parameters['tempDir'];
93
+        if (!Util::mwMkdir($parameters['tempDir'])) {
94
+            $res->messages[] = 'Temp dir does not exist '.$parameters['tempDir'];
95 95
 
96 96
             return $res;
97 97
         }
98 98
 
99 99
         $fileName                           = pathinfo($parameters['resumableFilename'], PATHINFO_FILENAME);
100
-        $fileName                           = preg_replace( '/[\W]/', '', $fileName);
101
-        if (strlen($fileName)<10){
100
+        $fileName                           = preg_replace('/[\W]/', '', $fileName);
101
+        if (strlen($fileName) < 10) {
102 102
             $fileName = ''.md5(time()).'-'.$fileName;
103 103
         }
104
-        $fileName                           .= '.'.pathinfo($parameters['resumableFilename'], PATHINFO_EXTENSION);
104
+        $fileName .= '.'.pathinfo($parameters['resumableFilename'], PATHINFO_EXTENSION);
105 105
         $parameters['resumableFilename']    = $fileName;
106 106
         $parameters['fullUploadedFileName'] = "{$parameters['tempDir']}/{$fileName}";
107 107
 
@@ -115,8 +115,8 @@  discard block
 block discarded – undo
115 115
         }
116 116
 
117 117
         foreach ($parameters['files'] as $file_data) {
118
-            if ( ! self::moveUploadedPartToSeparateDir($parameters, $file_data)) {
119
-                $res->messages[] = 'Does not found any uploaded chunks on with path ' . $file_data['file_path'];
118
+            if (!self::moveUploadedPartToSeparateDir($parameters, $file_data)) {
119
+                $res->messages[] = 'Does not found any uploaded chunks on with path '.$file_data['file_path'];
120 120
 
121 121
                 return $res;
122 122
             }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
      */
145 145
     private static function moveUploadedPartToSeparateDir(array $parameters, array $file_data): bool
146 146
     {
147
-        if ( ! file_exists($file_data['file_path'])) {
147
+        if (!file_exists($file_data['file_path'])) {
148 148
             return false;
149 149
         }
150 150
         $factory          = new StreamFactory();
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
     {
178 178
         $totalFilesOnServerSize = 0;
179 179
         foreach (scandir($parameters['tempDir']) as $file) {
180
-            $totalFilesOnServerSize += filesize($parameters['tempDir'] . '/' . $file);
180
+            $totalFilesOnServerSize += filesize($parameters['tempDir'].'/'.$file);
181 181
         }
182 182
 
183 183
         if ($totalFilesOnServerSize >= $parameters['resumableTotalSize']) {
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
                 'resumableTotalSize'   => $parameters['resumableTotalSize'],
190 190
                 'resumableTotalChunks' => $parameters['resumableTotalChunks'],
191 191
             ];
192
-            $settings_file  = "{$parameters['tempDir']}/merge_settings";
192
+            $settings_file = "{$parameters['tempDir']}/merge_settings";
193 193
             file_put_contents(
194 194
                 $settings_file,
195 195
                 json_encode($merge_settings, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT)
@@ -226,22 +226,22 @@  discard block
 block discarded – undo
226 226
         $uploadDir = $di->getShared('config')->path('www.uploadDir');
227 227
 
228 228
         $upload_id     = $postData['id'] ?? null;
229
-        $progress_dir  = $uploadDir . '/' . $upload_id;
230
-        $progress_file = $progress_dir . '/merging_progress';
229
+        $progress_dir  = $uploadDir.'/'.$upload_id;
230
+        $progress_file = $progress_dir.'/merging_progress';
231 231
         if (empty($upload_id)) {
232 232
             $res->success                   = false;
233 233
             $res->data['d_status_progress'] = '0';
234 234
             $res->data['d_status']          = 'ID_NOT_SET';
235 235
             $res->messages[]                = 'Upload ID does not set';
236
-        } elseif ( ! file_exists($progress_file) && file_exists($progress_dir)) {
236
+        } elseif (!file_exists($progress_file) && file_exists($progress_dir)) {
237 237
             $res->success                   = true;
238 238
             $res->data['d_status_progress'] = '0';
239 239
             $res->data['d_status']          = 'INPROGRESS';
240
-        } elseif ( ! file_exists($progress_dir)) {
240
+        } elseif (!file_exists($progress_dir)) {
241 241
             $res->success                   = false;
242 242
             $res->data['d_status_progress'] = '0';
243 243
             $res->data['d_status']          = 'NOT_FOUND';
244
-            $res->messages[]                = 'Does not found anything with path: ' . $progress_dir;
244
+            $res->messages[]                = 'Does not found anything with path: '.$progress_dir;
245 245
         } elseif ('100' === file_get_contents($progress_file)) {
246 246
             $res->success                   = true;
247 247
             $res->data['d_status_progress'] = '100';
@@ -267,14 +267,14 @@  discard block
 block discarded – undo
267 267
         $res            = new PBXApiResult();
268 268
         $res->processor = __METHOD__;
269 269
         $extension      = Util::getExtensionOfFile($filePath);
270
-        if ( ! in_array($extension, ['mp3', 'wav', 'alaw'])) {
270
+        if (!in_array($extension, ['mp3', 'wav', 'alaw'])) {
271 271
             $res->success    = false;
272 272
             $res->messages[] = "It is forbidden to remove the file type $extension.";
273 273
 
274 274
             return $res;
275 275
         }
276 276
 
277
-        if ( ! file_exists($filePath)) {
277
+        if (!file_exists($filePath)) {
278 278
             $res->success         = true;
279 279
             $res->data['message'] = "File '{$filePath}' already deleted";
280 280
 
@@ -284,13 +284,13 @@  discard block
 block discarded – undo
284 284
         $out = [];
285 285
 
286 286
         $arrDeletedFiles = [
287
-            escapeshellarg(Util::trimExtensionForFile($filePath) . ".wav"),
288
-            escapeshellarg(Util::trimExtensionForFile($filePath) . ".mp3"),
289
-            escapeshellarg(Util::trimExtensionForFile($filePath) . ".alaw"),
287
+            escapeshellarg(Util::trimExtensionForFile($filePath).".wav"),
288
+            escapeshellarg(Util::trimExtensionForFile($filePath).".mp3"),
289
+            escapeshellarg(Util::trimExtensionForFile($filePath).".alaw"),
290 290
         ];
291 291
 
292 292
         $rmPath = Util::which('rm');
293
-        Util::mwExec("{$rmPath} -rf " . implode(' ', $arrDeletedFiles), $out);
293
+        Util::mwExec("{$rmPath} -rf ".implode(' ', $arrDeletedFiles), $out);
294 294
         if (file_exists($filePath)) {
295 295
             $res->success  = false;
296 296
             $res->messages = $out;
@@ -323,13 +323,13 @@  discard block
 block discarded – undo
323 323
             $cat          = Util::which('cat');
324 324
             $di           = Di::getDefault();
325 325
             $dirsConfig   = $di->getShared('config');
326
-            $filenameTmp  = $dirsConfig->path('www.downloadCacheDir') . '/' . __FUNCTION__ . '_' . time() . '.conf';
326
+            $filenameTmp  = $dirsConfig->path('www.downloadCacheDir').'/'.__FUNCTION__.'_'.time().'.conf';
327 327
             $cmd          = "{$cat} {$filename} > {$filenameTmp}";
328 328
             Util::mwExec("{$cmd}; chown www:www {$filenameTmp}");
329 329
             $res->data['filename'] = $filenameTmp;
330 330
         } else {
331 331
             $res->success    = false;
332
-            $res->messages[] = 'No access to the file ' . $filename;
332
+            $res->messages[] = 'No access to the file '.$filename;
333 333
         }
334 334
 
335 335
         return $res;
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
         $res->success   = true;
399 399
 
400 400
         $firmwareDirTmp = dirname($imgFileName);
401
-        $progress_file  = $firmwareDirTmp . '/progress';
401
+        $progress_file  = $firmwareDirTmp.'/progress';
402 402
 
403 403
         // Wait until download process started
404 404
         $d_pid = Util::getPidOfProcess("{$firmwareDirTmp}/download_settings.json");
@@ -410,7 +410,7 @@  discard block
 block discarded – undo
410 410
             $error = trim(file_get_contents("{$firmwareDirTmp}/error"));
411 411
         }
412 412
 
413
-        if ( ! file_exists($progress_file)) {
413
+        if (!file_exists($progress_file)) {
414 414
             $res->data['d_status_progress'] = '0';
415 415
             $res->messages[]                = 'NOT_FOUND';
416 416
             $res->success                   = false;
@@ -514,11 +514,11 @@  discard block
 block discarded – undo
514 514
         } else {
515 515
             $tempDir = '/tmp';
516 516
         }
517
-        $moduleDirTmp  = $tempDir . '/' . $moduleUniqueID;
518
-        $progress_file = $moduleDirTmp . '/progress';
517
+        $moduleDirTmp  = $tempDir.'/'.$moduleUniqueID;
518
+        $progress_file = $moduleDirTmp.'/progress';
519 519
         $error         = '';
520
-        if (file_exists($moduleDirTmp . '/error')) {
521
-            $error = trim(file_get_contents($moduleDirTmp . '/error'));
520
+        if (file_exists($moduleDirTmp.'/error')) {
521
+            $error = trim(file_get_contents($moduleDirTmp.'/error'));
522 522
         }
523 523
 
524 524
         // Wait until download process started
@@ -527,7 +527,7 @@  discard block
 block discarded – undo
527 527
             usleep(500000);
528 528
         }
529 529
 
530
-        if ( ! file_exists($progress_file)) {
530
+        if (!file_exists($progress_file)) {
531 531
             $res->data['d_status_progress'] = '0';
532 532
             $res->data['d_status']          = 'NOT_FOUND';
533 533
             $res->success                   = false;
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
             $res->data['d_status']          = 'DOWNLOAD_ERROR';
536 536
             $res->data['d_status_progress'] = file_get_contents($progress_file);
537 537
             $res->data['d_error']           = $error;
538
-            $res->messages[]                = file_get_contents($moduleDirTmp . '/error');
538
+            $res->messages[]                = file_get_contents($moduleDirTmp.'/error');
539 539
             $res->success                   = false;
540 540
         } elseif ('100' === file_get_contents($progress_file)) {
541 541
             $res->data['d_status_progress'] = '100';
@@ -544,11 +544,11 @@  discard block
 block discarded – undo
544 544
             $res->success                   = true;
545 545
         } else {
546 546
             $res->data['d_status_progress'] = file_get_contents($progress_file);
547
-            $d_pid                          = Util::getPidOfProcess($moduleDirTmp . '/download_settings.json');
547
+            $d_pid                          = Util::getPidOfProcess($moduleDirTmp.'/download_settings.json');
548 548
             if (empty($d_pid)) {
549 549
                 $res->data['d_status'] = 'DOWNLOAD_ERROR';
550
-                if (file_exists($moduleDirTmp . '/error')) {
551
-                    $res->messages[] = file_get_contents($moduleDirTmp . '/error');
550
+                if (file_exists($moduleDirTmp.'/error')) {
551
+                    $res->messages[] = file_get_contents($moduleDirTmp.'/error');
552 552
                 } else {
553 553
                     $res->messages[] = "Download process interrupted at {$res->data['d_status_progress']}%";
554 554
                 }
@@ -579,13 +579,13 @@  discard block
 block discarded – undo
579 579
             $grepPath    = Util::which('grep');
580 580
             $echoPath    = Util::which('echo');
581 581
             $awkPath     = Util::which('awk');
582
-            $cmd         = 'f="' . $filePath . '"; p=`' . $sevenZaPath . ' l $f | ' . $grepPath . ' module.json`;if [ "$?" == "0" ]; then ' . $sevenZaPath . ' -so e -y -r $f `' . $echoPath . ' $p |  ' . $awkPath . ' -F" " \'{print $6}\'`; fi';
582
+            $cmd         = 'f="'.$filePath.'"; p=`'.$sevenZaPath.' l $f | '.$grepPath.' module.json`;if [ "$?" == "0" ]; then '.$sevenZaPath.' -so e -y -r $f `'.$echoPath.' $p |  '.$awkPath.' -F" " \'{print $6}\'`; fi';
583 583
 
584 584
             Util::mwExec($cmd, $out);
585 585
             $settings = json_decode(implode("\n", $out), true);
586 586
 
587 587
             $moduleUniqueID = $settings['moduleUniqueID'] ?? null;
588
-            if ( ! $moduleUniqueID) {
588
+            if (!$moduleUniqueID) {
589 589
                 $res->messages[] = 'The" moduleUniqueID " in the module file is not described.the json or file does not exist.';
590 590
 
591 591
                 return $res;
Please login to merge, or discard this patch.