Passed
Push — master ( fd784d...93a118 )
by Evgenii
02:59
created
src/logic/VideoFrameExtractor.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -19,14 +19,17 @@  discard block
 block discarded – undo
19 19
     {
20 20
         $this->ffmpegBin = Yii::$app->getModule('files')->ffmpeg;
21 21
 
22
-        if (!file_exists($this->ffmpegBin))
23
-            throw new ErrorException("ffmpeg is not found: {$this->ffmpegBin}");
22
+        if (!file_exists($this->ffmpegBin)) {
23
+                    throw new ErrorException("ffmpeg is not found: {$this->ffmpegBin}");
24
+        }
24 25
 
25
-        if (!is_executable($this->ffmpegBin))
26
-            throw new ErrorException("ffmpeg is not executable: {$this->ffmpegBin}");
26
+        if (!is_executable($this->ffmpegBin)) {
27
+                    throw new ErrorException("ffmpeg is not executable: {$this->ffmpegBin}");
28
+        }
27 29
 
28
-        if (!is_file($videoSourceFilename))
29
-            throw new ErrorException('File not found on disk.');
30
+        if (!is_file($videoSourceFilename)) {
31
+                    throw new ErrorException('File not found on disk.');
32
+        }
30 33
 
31 34
         $this->videoSourceFilename = $videoSourceFilename;
32 35
         $this->outputImageFilename = $outputImageFilename;
@@ -39,8 +42,9 @@  discard block
 block discarded – undo
39 42
     {
40 43
         $command = "{$this->ffmpegBin} -i {$this->videoSourceFilename}  -ss 00:00:03.000 -vframes 1  {$this->outputImageFilename}";
41 44
         exec($command, $out, $result);
42
-        if ($result !== 0)
43
-            throw new ErrorException('FFmpeg frame extracting fail:' . print_r($out, true));
45
+        if ($result !== 0) {
46
+                    throw new ErrorException('FFmpeg frame extracting fail:' . print_r($out, true));
47
+        }
44 48
     }
45 49
 
46 50
 }
Please login to merge, or discard this patch.
src/controllers/DefaultController.php 1 patch
Braces   +18 added lines, -12 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");
@@ -165,8 +168,9 @@  discard block
 block discarded – undo
165 168
 
166 169
         $view = Yii::$app->request->post('mode') == 'single' ? "_single" : "_file";
167 170
 
168
-        if ($ratio)
169
-            $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
171
+        if ($ratio) {
172
+                    $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
173
+        }
170 174
 
171 175
         return $this->renderAjax($view, [
172 176
             'model' => $model,
@@ -192,8 +196,9 @@  discard block
 block discarded – undo
192 196
     {
193 197
         $model = File::findOne(['hash' => $hash]);
194 198
 
195
-        if (!$model)
196
-            throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
199
+        if (!$model) {
200
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
201
+        }
197 202
 
198 203
         $response = Yii::$app->response;
199 204
         $response->format = Response::FORMAT_RAW;
@@ -202,8 +207,9 @@  discard block
 block discarded – undo
202 207
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
203 208
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
204 209
 
205
-        if (!file_exists($model->getRootPreviewPath()))
206
-            throw new NotFoundHttpException('Preview not found.');
210
+        if (!file_exists($model->getRootPreviewPath())) {
211
+                    throw new NotFoundHttpException('Preview not found.');
212
+        }
207 213
 
208 214
         $response->sendFile($model->getRootPreviewPath(), 'preview.jpg');
209 215
 
Please login to merge, or discard this patch.
src/components/PictureWidget.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -28,11 +28,13 @@
 block discarded – undo
28 28
      */
29 29
     public function run(): ?string
30 30
     {
31
-        if (empty($this->model) || !in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO]))
32
-            return null;
31
+        if (empty($this->model) || !in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) {
32
+                    return null;
33
+        }
33 34
 
34
-        if (is_array($this->width))
35
-            $this->view = 'mediaPictureWidget';
35
+        if (is_array($this->width)) {
36
+                    $this->view = 'mediaPictureWidget';
37
+        }
36 38
 
37 39
         return $this->render($this->view, [
38 40
             'model' => $this->model,
Please login to merge, or discard this patch.
src/components/FileBehaviour.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -205,7 +205,7 @@
 block discarded – undo
205 205
         if (isset($this->_values[$att_name])) {
206 206
             unset($this->_values[$att_name][0]);
207 207
             if (sizeof($this->_values[$att_name]))
208
-                return array_map(function ($fileId) {
208
+                return array_map(function($fileId) {
209 209
                     return File::findOne($fileId);
210 210
                 }, $this->_values[$att_name]);
211 211
         } else {
Please login to merge, or discard this patch.
Braces   +24 added lines, -15 removed lines patch added patch discarded remove patch
@@ -69,9 +69,11 @@  discard block
 block discarded – undo
69 69
                     ]
70 70
                 )->execute();
71 71
 
72
-                if ($ids) foreach ($ids as $id) {
72
+                if ($ids) {
73
+                    foreach ($ids as $id) {
73 74
                     if (empty($id))
74 75
                         continue;
76
+                }
75 77
                     $file = File::findOne($id);
76 78
                     if ($file) {
77 79
                         $file->object_id = $this->owner->id;
@@ -106,8 +108,9 @@  discard block
 block discarded – undo
106 108
                 in_array($this->owner->scenario, $params['requiredOn']) &&
107 109
                 !in_array($this->owner->scenario, $params['requiredExcept']) &&
108 110
                 !isset($this->_values[$attributeIds][1])
109
-            )
110
-                $this->owner->addError($attributeName, $params['requiredMessage']);
111
+            ) {
112
+                            $this->owner->addError($attributeName, $params['requiredMessage']);
113
+            }
111 114
         }
112 115
     }
113 116
 
@@ -124,8 +127,8 @@  discard block
 block discarded – undo
124 127
         $validators = $owner->validators;
125 128
 
126 129
         // Пробегаемся по валидаторам и вычисляем, какие из них касаются наших файл-полей
127
-        if ($validators)
128
-            foreach ($validators as $key => $validator) {
130
+        if ($validators) {
131
+                    foreach ($validators as $key => $validator) {
129 132
 
130 133
                 // Сначала пробегаемся по файловым валидаторам
131 134
                 if ($validator::className() == 'yii\validators\FileValidator' || $validator::className() == 'floor12\files\components\ReformatValidator') {
@@ -133,6 +136,7 @@  discard block
 block discarded – undo
133 136
 
134 137
                         if (is_string($params)) {
135 138
                             $field = $params;
139
+        }
136 140
                             $params = [];
137 141
                         }
138 142
 
@@ -168,8 +172,10 @@  discard block
 block discarded – undo
168 172
             }
169 173
 
170 174
         // Добавляем дефолтный валидатор для прилетающих айдишников
171
-        if ($this->attributes) foreach ($this->attributes as $fieldName => $fieldParams) {
175
+        if ($this->attributes) {
176
+            foreach ($this->attributes as $fieldName => $fieldParams) {
172 177
             $validator = Validator::createValidator('safe', $owner, ["{$fieldName}_ids"]);
178
+        }
173 179
             $validators->append($validator);
174 180
         }
175 181
     }
@@ -190,8 +196,9 @@  discard block
 block discarded – undo
190 196
      */
191 197
     public function canSetProperty($name, $checkVars = true)
192 198
     {
193
-        if (array_key_exists($this->getRealAttributeName($name), $this->attributes))
194
-            return true;
199
+        if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) {
200
+                    return true;
201
+        }
195 202
 
196 203
         return parent::canSetProperty($name, $checkVars = true);
197 204
     }
@@ -204,9 +211,10 @@  discard block
 block discarded – undo
204 211
     {
205 212
         if (isset($this->_values[$att_name])) {
206 213
             unset($this->_values[$att_name][0]);
207
-            if (sizeof($this->_values[$att_name]))
208
-                return array_map(function ($fileId) {
214
+            if (sizeof($this->_values[$att_name])) {
215
+                            return array_map(function ($fileId) {
209 216
                     return File::findOne($fileId);
217
+            }
210 218
                 }, $this->_values[$att_name]);
211 219
         } else {
212 220
             if (!isset($this->cachedFiles[$att_name])) {
@@ -214,8 +222,8 @@  discard block
 block discarded – undo
214 222
                     isset($this->attributes[$att_name]['validator']) &&
215 223
                     isset($this->attributes[$att_name]['validator']['yii\validators\FileValidator']) &&
216 224
                     $this->attributes[$att_name]['validator']['yii\validators\FileValidator']->maxFiles > 1
217
-                )
218
-                    $this->cachedFiles[$att_name] = File::find()
225
+                ) {
226
+                                    $this->cachedFiles[$att_name] = File::find()
219 227
                         ->where(
220 228
                             [
221 229
                                 'object_id' => $this->owner->id,
@@ -224,7 +232,7 @@  discard block
 block discarded – undo
224 232
                             ])
225 233
                         ->orderBy('ordering ASC')
226 234
                         ->all();
227
-                else {
235
+                } else {
228 236
                     $this->cachedFiles[$att_name] = File::find()
229 237
                         ->where(
230 238
                             [
@@ -249,8 +257,9 @@  discard block
 block discarded – undo
249 257
     {
250 258
         $attribute = $this->getRealAttributeName($name);
251 259
 
252
-        if (array_key_exists($attribute, $this->attributes))
253
-            $this->_values[$attribute] = $value;
260
+        if (array_key_exists($attribute, $this->attributes)) {
261
+                    $this->_values[$attribute] = $value;
262
+        }
254 263
     }
255 264
 
256 265
 
Please login to merge, or discard this patch.
src/components/FileListWidget.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -30,8 +30,9 @@  discard block
 block discarded – undo
30 30
      */
31 31
     public function init()
32 32
     {
33
-        if (empty($this->files))
34
-            return null;
33
+        if (empty($this->files)) {
34
+                    return null;
35
+        }
35 36
         Yii::$app->getModule('files')->registerTranslations();
36 37
         if (empty($this->lightboxKey)) {
37 38
             $this->lightboxKey = $this->files[0]->field . '-' . $this->files[0]->object_id;
@@ -50,8 +51,9 @@  discard block
 block discarded – undo
50 51
 
51 52
         $this->getView()->registerJs("yiiDownloadAllLink = '" . Url::toRoute('files/default/zip') . "'", View::POS_BEGIN, 'yiiDownloadAllLink');
52 53
 
53
-        if ($this->passFirst && sizeof($this->files) > 0)
54
-            $this->files = array_slice($this->files, 1);
54
+        if ($this->passFirst && sizeof($this->files) > 0) {
55
+                    $this->files = array_slice($this->files, 1);
56
+        }
55 57
 
56 58
 
57 59
         return $this->render('fileListWidget', [
Please login to merge, or discard this patch.
src/components/FileInputWidget.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@
 block discarded – undo
37 37
         $this->registerTranslations();
38 38
         $this->block_id = rand(9999999, 999999999);
39 39
 
40
-        if (!$this->uploadButtonText)
41
-            $this->uploadButtonText = Yii::t('files', 'Upload');
40
+        if (!$this->uploadButtonText) {
41
+                    $this->uploadButtonText = Yii::t('files', 'Upload');
42
+        }
42 43
 
43 44
         $this->ratio = $this->model->getBehavior('files')->attributes[$this->attribute]['ratio'] ?? null;
44 45
 
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[array_key_first($model)];
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.
src/logic/ImagePreviewer.php 1 patch
Braces   +33 added lines, -22 removed lines patch added patch discarded remove patch
@@ -31,8 +31,9 @@  discard block
 block discarded – undo
31 31
         $this->webp = $webp;
32 32
         $this->quality = $quality;
33 33
 
34
-        if (!$this->model->isImage() && !$this->model->isVideo())
35
-            throw new ErrorException('File is not an image or video.');
34
+        if (!$this->model->isImage() && !$this->model->isVideo()) {
35
+                    throw new ErrorException('File is not an image or video.');
36
+        }
36 37
     }
37 38
 
38 39
     /**
@@ -42,8 +43,9 @@  discard block
 block discarded – undo
42 43
      */
43 44
     public function getUrl()
44 45
     {
45
-        if ($this->model->isSvg())
46
-            return $this->model->getRootPath();
46
+        if ($this->model->isSvg()) {
47
+                    return $this->model->getRootPath();
48
+        }
47 49
 
48 50
         $cachePath = Yii::$app->getModule('files')->cacheFullPath;
49 51
         $jpegName = $this->model->makeNameWithSize($this->model->filename, $this->width, false, $this->quality);
@@ -57,21 +59,25 @@  discard block
 block discarded – undo
57 59
         $sourceImagePath = $this->model->rootPath;
58 60
         if ($this->model->isVideo()) {
59 61
             $sourceImagePath = $this->fileName . '.jpeg';
60
-            if (!is_file($sourceImagePath))
61
-                Yii::createObject(VideoFrameExtractor::class, [
62
+            if (!is_file($sourceImagePath)) {
63
+                            Yii::createObject(VideoFrameExtractor::class, [
62 64
                     $this->model->rootPath,
63 65
                     $sourceImagePath
64 66
                 ])->extract();
67
+            }
65 68
         }
66 69
 
67
-        if (!is_file($this->fileName) || filesize($this->fileName) == 0)
68
-            $this->createPreview($sourceImagePath);
70
+        if (!is_file($this->fileName) || filesize($this->fileName) == 0) {
71
+                    $this->createPreview($sourceImagePath);
72
+        }
69 73
 
70
-        if ($this->webp && !file_exists($this->fileNameWebp))
71
-            $this->createPreviewWebp();
74
+        if ($this->webp && !file_exists($this->fileNameWebp)) {
75
+                    $this->createPreviewWebp();
76
+        }
72 77
 
73
-        if ($this->webp)
74
-            return $this->fileNameWebp;
78
+        if ($this->webp) {
79
+                    return $this->fileNameWebp;
80
+        }
75 81
 
76 82
         return $this->fileName;
77 83
     }
@@ -81,19 +87,23 @@  discard block
 block discarded – undo
81 87
      */
82 88
     protected function prepareFolder()
83 89
     {
84
-        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath))
85
-            mkdir(Yii::$app->getModule('files')->cacheFullPath);
90
+        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) {
91
+                    mkdir(Yii::$app->getModule('files')->cacheFullPath);
92
+        }
86 93
         $lastFolder = '/';
87 94
         $explodes = explode('/', $this->fileName);
88 95
         array_pop($explodes);
89
-        if (empty($explodes))
90
-            return;
96
+        if (empty($explodes)) {
97
+                    return;
98
+        }
91 99
         foreach ($explodes as $folder) {
92
-            if (empty($folder))
93
-                continue;
100
+            if (empty($folder)) {
101
+                            continue;
102
+            }
94 103
             $lastFolder = $lastFolder . $folder . '/';
95
-            if (!file_exists($lastFolder))
96
-                mkdir($lastFolder);
104
+            if (!file_exists($lastFolder)) {
105
+                            mkdir($lastFolder);
106
+            }
97 107
         }
98 108
     }
99 109
 
@@ -116,8 +126,9 @@  discard block
 block discarded – undo
116 126
         }
117 127
 
118 128
         $saveType = $img->image_type;
119
-        if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC)
120
-            $saveType = IMG_JPEG;
129
+        if ($saveType == IMG_WEBP || $saveType == IMG_QUADRATIC) {
130
+                    $saveType = IMG_JPEG;
131
+        }
121 132
         $img->save($this->fileName, $saveType, $this->quality);
122 133
     }
123 134
 
Please login to merge, or discard this patch.
src/actions/GetPreviewAction.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -54,14 +54,17 @@  discard block
 block discarded – undo
54 54
     private function loadAndCheckModel(string $hash): void
55 55
     {
56 56
         $this->model = File::findOne(['hash' => $hash]);
57
-        if (!$this->model)
58
-            throw new NotFoundHttpException("Запрашиваемый файл не найден");
57
+        if (!$this->model) {
58
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден");
59
+        }
59 60
 
60
-        if (!$this->model->isImage() && !$this->model->isVideo())
61
-            throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
61
+        if (!$this->model->isImage() && !$this->model->isVideo()) {
62
+                    throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
63
+        }
62 64
 
63
-        if (!file_exists($this->model->rootPath))
64
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
65
+        if (!file_exists($this->model->rootPath)) {
66
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
67
+        }
65 68
     }
66 69
 
67 70
     /**
@@ -73,8 +76,9 @@  discard block
 block discarded – undo
73 76
     protected function sendPreview($width, $webp, $quality)
74 77
     {
75 78
         $filename = Yii::createObject(ImagePreviewer::class, [$this->model, $width, $webp, $quality])->getUrl();
76
-        if (!file_exists($filename))
77
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
79
+        if (!file_exists($filename)) {
80
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
81
+        }
78 82
 
79 83
         $response = Yii::$app->response;
80 84
         $response->format = Response::FORMAT_RAW;
Please login to merge, or discard this patch.