Completed
Push — master ( a6ff39...35f799 )
by Evgenii
05:41 queued 14s
created
src/logic/ImagePreviewer.php 1 patch
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
         $this->width = $width;
32 32
         $this->webp = $webp;
33 33
 
34
-        if ($this->model->type != FileType::IMAGE)
35
-            throw new ErrorException('File is not an image.');
34
+        if ($this->model->type != FileType::IMAGE) {
35
+                    throw new ErrorException('File is not an image.');
36
+        }
36 37
     }
37 38
 
38 39
     /**
@@ -40,22 +41,26 @@  discard block
 block discarded – undo
40 41
      */
41 42
     public function getUrl()
42 43
     {
43
-        if ($this->model->isSvg())
44
-            return $this->model->getRootPath();
44
+        if ($this->model->isSvg()) {
45
+                    return $this->model->getRootPath();
46
+        }
45 47
 
46 48
         $this->fileName = Yii::$app->getModule('files')->cacheFullPath . $this->model->makeNameWithSize($this->model->filename, $this->width, 0);
47 49
         $this->fileNameWebp = Yii::$app->getModule('files')->cacheFullPath . $this->model->makeNameWithSize($this->model->filename, $this->width, 0, true);
48 50
 
49 51
         $this->prepareFolders();
50 52
 
51
-        if (!file_exists($this->fileName) || filesize($this->fileName) == 0)
52
-            $this->createPreview();
53
+        if (!file_exists($this->fileName) || filesize($this->fileName) == 0) {
54
+                    $this->createPreview();
55
+        }
53 56
 
54
-        if ($this->webp && !file_exists($this->fileNameWebp))
55
-            $this->createPreviewWebp();
57
+        if ($this->webp && !file_exists($this->fileNameWebp)) {
58
+                    $this->createPreviewWebp();
59
+        }
56 60
 
57
-        if ($this->webp)
58
-            return $this->fileNameWebp;
61
+        if ($this->webp) {
62
+                    return $this->fileNameWebp;
63
+        }
59 64
 
60 65
         return $this->fileName;
61 66
     }
@@ -65,17 +70,21 @@  discard block
 block discarded – undo
65 70
      */
66 71
     protected function prepareFolders()
67 72
     {
68
-        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath))
69
-            mkdir(Yii::$app->getModule('files')->cacheFullPath);
73
+        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) {
74
+                    mkdir(Yii::$app->getModule('files')->cacheFullPath);
75
+        }
70 76
 
71 77
         preg_match('/(.+\/\d{2})\/\d{2}\//', $this->fileName, $matches);
72 78
 
73
-        if (!file_exists($matches[1]))
74
-            @mkdir($matches[1]);
75
-        if (!file_exists($matches[0]))
76
-            @mkdir($matches[0]);
77
-        if (!file_exists($matches[0]))
78
-            throw new ErrorException("Unable to create cache folder: {$matches[0]}");
79
+        if (!file_exists($matches[1])) {
80
+                    @mkdir($matches[1]);
81
+        }
82
+        if (!file_exists($matches[0])) {
83
+                    @mkdir($matches[0]);
84
+        }
85
+        if (!file_exists($matches[0])) {
86
+                    throw new ErrorException("Unable to create cache folder: {$matches[0]}");
87
+        }
79 88
     }
80 89
 
81 90
     /**
Please login to merge, or discard this patch.
src/logic/PathGenerator.php 1 patch
Braces   +15 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,14 +20,17 @@  discard block
 block discarded – undo
20 20
     public function __construct($storagePath)
21 21
     {
22 22
 
23
-        if (!$storagePath)
24
-            throw new ErrorException('Storage path not set for path generator.');
23
+        if (!$storagePath) {
24
+                    throw new ErrorException('Storage path not set for path generator.');
25
+        }
25 26
 
26
-        if (!file_exists($storagePath))
27
-            mkdir($storagePath);
27
+        if (!file_exists($storagePath)) {
28
+                    mkdir($storagePath);
29
+        }
28 30
 
29
-        if (!file_exists($storagePath))
30
-            throw new ErrorException('Unable to create storage.');
31
+        if (!file_exists($storagePath)) {
32
+                    throw new ErrorException('Unable to create storage.');
33
+        }
31 34
 
32 35
         $folderName0 = rand(10, 99);
33 36
         $folderName1 = rand(10, 99);
@@ -38,10 +41,12 @@  discard block
 block discarded – undo
38 41
         $fullPath0 = $storagePath . $path0;
39 42
         $fullPath1 = $storagePath . $path1;
40 43
 
41
-        if (!file_exists($fullPath0))
42
-            mkdir($fullPath0);
43
-        if (!file_exists($fullPath1))
44
-            mkdir($fullPath1);
44
+        if (!file_exists($fullPath0)) {
45
+                    mkdir($fullPath0);
46
+        }
47
+        if (!file_exists($fullPath1)) {
48
+                    mkdir($fullPath1);
49
+        }
45 50
 
46 51
         $this->path = $path1 . DIRECTORY_SEPARATOR . md5(rand(0, 1000) . time());
47 52
     }
Please login to merge, or discard this patch.
src/controllers/DefaultController.php 1 patch
Braces   +36 added lines, -24 removed lines patch added patch discarded remove patch
@@ -73,8 +73,9 @@  discard block
 block discarded – undo
73 73
      */
74 74
     private function checkFormToken()
75 75
     {
76
-        if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken'))
77
-            throw new BadRequestHttpException('File-form token is wrong or missing.');
76
+        if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) {
77
+                    throw new BadRequestHttpException('File-form token is wrong or missing.');
78
+        }
78 79
     }
79 80
 
80 81
     /**
@@ -87,12 +88,14 @@  discard block
 block discarded – undo
87 88
 
88 89
         $zip = new  ZipArchive;
89 90
         $filename = Yii::getAlias("@webroot/assets/files.zip");
90
-        if (file_exists($filename))
91
-            @unlink($filename);
91
+        if (file_exists($filename)) {
92
+                    @unlink($filename);
93
+        }
92 94
         if (sizeof($files) && $zip->open($filename, ZipArchive::CREATE)) {
93 95
 
94
-            foreach ($files as $file)
95
-                $zip->addFile($file->rootPath, $file->title);
96
+            foreach ($files as $file) {
97
+                            $zip->addFile($file->rootPath, $file->title);
98
+            }
96 99
 
97 100
             $zip->close();
98 101
             header("Pragma: public");
@@ -164,8 +167,9 @@  discard block
 block discarded – undo
164 167
 
165 168
         $view = Yii::$app->request->post('mode') == 'single' ? "_single" : "_file";
166 169
 
167
-        if ($ratio)
168
-            $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
170
+        if ($ratio) {
171
+                    $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
172
+        }
169 173
 
170 174
         return $this->renderAjax($view, [
171 175
             'model' => $model,
@@ -182,11 +186,13 @@  discard block
 block discarded – undo
182 186
     {
183 187
         $model = File::findOne(['hash' => $hash]);
184 188
 
185
-        if (!$model)
186
-            throw new NotFoundHttpException("Запрашиваемый файл не найден");
189
+        if (!$model) {
190
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден");
191
+        }
187 192
 
188
-        if (!file_exists($model->rootPath))
189
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
193
+        if (!file_exists($model->rootPath)) {
194
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
195
+        }
190 196
 
191 197
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
192 198
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
@@ -216,14 +222,17 @@  discard block
 block discarded – undo
216 222
     {
217 223
         $model = File::findOne(['hash' => $hash]);
218 224
 
219
-        if (!$model)
220
-            throw new NotFoundHttpException("Запрашиваемый файл не найден");
225
+        if (!$model) {
226
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден");
227
+        }
221 228
 
222
-        if ($model->type != FileType::IMAGE)
223
-            throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
229
+        if ($model->type != FileType::IMAGE) {
230
+                    throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
231
+        }
224 232
 
225
-        if (!file_exists($model->rootPath))
226
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
233
+        if (!file_exists($model->rootPath)) {
234
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
235
+        }
227 236
 
228 237
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
229 238
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
@@ -233,8 +242,9 @@  discard block
 block discarded – undo
233 242
 
234 243
             $filename = Yii::createObject(ImagePreviewer::class, [$model, $width, $webp])->getUrl();
235 244
 
236
-            if (!file_exists($filename))
237
-                throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
245
+            if (!file_exists($filename)) {
246
+                            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
247
+            }
238 248
 
239 249
             $response = Yii::$app->response;
240 250
             $response->format = Response::FORMAT_RAW;
@@ -275,8 +285,9 @@  discard block
 block discarded – undo
275 285
     {
276 286
         $model = File::findOne(['hash' => $hash]);
277 287
 
278
-        if (!$model)
279
-            throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
288
+        if (!$model) {
289
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
290
+        }
280 291
 
281 292
         $response = Yii::$app->response;
282 293
         $response->format = Response::FORMAT_RAW;
@@ -285,8 +296,9 @@  discard block
 block discarded – undo
285 296
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
286 297
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
287 298
 
288
-        if (!file_exists($model->rootPreviewPath))
289
-            throw new NotFoundHttpException('Preview not found.');
299
+        if (!file_exists($model->rootPreviewPath)) {
300
+                    throw new NotFoundHttpException('Preview not found.');
301
+        }
290 302
 
291 303
         $response->sendFile($model->rootPreviewPath, 'preview.jpg');
292 304
 
Please login to merge, or discard this patch.
src/controllers/ConsoleController.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@
 block discarded – undo
46 46
         $commands[] = "find {$module->storageFullPath}  -regextype egrep -regex \".+/.{32}\..{3,4}\.jpg\" -exec rm -rf {} \;";
47 47
         $commands[] = "find {$module->cacheFullPath}  -regextype egrep -regex \".+/.{32}\..{3,4}\.jpg\" -exec rm -rf {} \;";
48 48
 
49
-        array_map(function ($command) {
49
+        array_map(function($command) {
50 50
             exec($command);
51 51
         }, $commands);
52 52
 
Please login to merge, or discard this patch.
Braces   +15 added lines, -9 removed lines patch added patch discarded remove patch
@@ -29,9 +29,11 @@  discard block
 block discarded – undo
29 29
     {
30 30
         $time = strtotime('- 6 hours');
31 31
         $files = File::find()->where("`object_id`=0 AND `created`<'{$time}'")->all();
32
-        if ($files) foreach ($files as $file) {
32
+        if ($files) {
33
+            foreach ($files as $file) {
33 34
             $file->delete();
34 35
         }
36
+        }
35 37
     }
36 38
 
37 39
     /**
@@ -60,22 +62,26 @@  discard block
 block discarded – undo
60 62
     {
61 63
         $ffmpeg = Yii::$app->getModule('files')->ffmpeg;
62 64
 
63
-        if (!file_exists($ffmpeg))
64
-            return $this->stdout("ffmpeg is not found: {$ffmpeg}" . PHP_EOL, Console::FG_RED);
65
+        if (!file_exists($ffmpeg)) {
66
+                    return $this->stdout("ffmpeg is not found: {$ffmpeg}" . PHP_EOL, Console::FG_RED);
67
+        }
65 68
 
66
-        if (!is_executable($ffmpeg))
67
-            return $this->stdout("ffmpeg is not executable: {$ffmpeg}" . PHP_EOL, Console::FG_RED);
69
+        if (!is_executable($ffmpeg)) {
70
+                    return $this->stdout("ffmpeg is not executable: {$ffmpeg}" . PHP_EOL, Console::FG_RED);
71
+        }
68 72
 
69 73
         $file = File::find()
70 74
             ->where(['type' => FileType::VIDEO, 'video_status' => VideoStatus::QUEUE])
71 75
             ->andWhere(['!=', 'object_id', 0])
72 76
             ->one();
73 77
 
74
-        if (!$file)
75
-            return $this->stdout("Convert queue is empty" . PHP_EOL, Console::FG_GREEN);
78
+        if (!$file) {
79
+                    return $this->stdout("Convert queue is empty" . PHP_EOL, Console::FG_GREEN);
80
+        }
76 81
 
77
-        if (!file_exists($file->rootPath))
78
-            return $this->stdout("Source file is not found: {$file->rootPath}" . PHP_EOL, Console::FG_RED);
82
+        if (!file_exists($file->rootPath)) {
83
+                    return $this->stdout("Source file is not found: {$file->rootPath}" . PHP_EOL, Console::FG_RED);
84
+        }
79 85
 
80 86
 
81 87
         $file->video_status = VideoStatus::CONVERTING;
Please login to merge, or discard this patch.
src/views/default/_single.php 1 patch
Braces   +7 added lines, -3 removed lines patch added patch discarded remove patch
@@ -17,8 +17,9 @@  discard block
 block discarded – undo
17 17
 use yii\helpers\Html;
18 18
 use yii\web\View;
19 19
 
20
-if (is_array($model))
20
+if (is_array($model)) {
21 21
     $model = $model[0];
22
+}
22 23
 
23 24
 $doc_contents = [
24 25
     'application/msword',
@@ -38,7 +39,8 @@  discard block
 block discarded – undo
38 39
             <?= Html::hiddenInput((new ReflectionClass($model->class))->getShortName() . "[{$model->field}_ids][]", $model->id) ?>
39 40
         </div>
40 41
 
41
-    <?php else: ?>
42
+    <?php else {
43
+    : ?>
42 44
 
43 45
         <div data-title="<?= $model->title ?>"
44 46
              id="yii2-file-object-<?= $model->id ?>"
@@ -52,7 +54,9 @@  discard block
 block discarded – undo
52 54
             <?php if ($model->type != FileType::IMAGE): ?>
53 55
                 <?= $model->icon ?>
54 56
                 <?= $model->title ?>
55
-            <?php endif; ?>
57
+            <?php endif;
58
+}
59
+?>
56 60
         </div>
57 61
     <?php endif; ?>
58 62
 
Please login to merge, or discard this patch.