Completed
Push — master ( c5eccd...ec8b64 )
by Evgenii
04:45
created
src/components/FileBehaviour.php 1 patch
Braces   +21 added lines, -13 removed lines patch added patch discarded remove patch
@@ -68,9 +68,11 @@  discard block
 block discarded – undo
68 68
                     ]
69 69
                 )->execute();
70 70
 
71
-                if ($ids) foreach ($ids as $id) {
71
+                if ($ids) {
72
+                    foreach ($ids as $id) {
72 73
                     if (empty($id))
73 74
                         continue;
75
+                }
74 76
                     $file = File::findOne($id);
75 77
                     if ($file) {
76 78
                         $file->object_id = $this->owner->id;
@@ -105,8 +107,9 @@  discard block
 block discarded – undo
105 107
                 in_array($this->owner->scenario, $params['requiredOn']) &&
106 108
                 !in_array($this->owner->scenario, $params['requiredExcept']) &&
107 109
                 !isset($this->_values[$attributeIds][1])
108
-            )
109
-                $this->owner->addError($attributeName, $params['requiredMessage']);
110
+            ) {
111
+                            $this->owner->addError($attributeName, $params['requiredMessage']);
112
+            }
110 113
         }
111 114
     }
112 115
 
@@ -123,8 +126,8 @@  discard block
 block discarded – undo
123 126
         $validators = $owner->validators;
124 127
 
125 128
         // Пробегаемся по валидаторам и вычисляем, какие из них касаются наших файл-полей
126
-        if ($validators)
127
-            foreach ($validators as $key => $validator) {
129
+        if ($validators) {
130
+                    foreach ($validators as $key => $validator) {
128 131
 
129 132
                 // Сначала пробегаемся по файловым валидаторам
130 133
                 if ($validator::className() == 'yii\validators\FileValidator' || $validator::className() == 'floor12\files\components\ReformatValidator') {
@@ -132,6 +135,7 @@  discard block
 block discarded – undo
132 135
 
133 136
                         if (is_string($params)) {
134 137
                             $field = $params;
138
+        }
135 139
                             $params = [];
136 140
                         }
137 141
 
@@ -167,8 +171,10 @@  discard block
 block discarded – undo
167 171
             }
168 172
 
169 173
         // Добавляем дефолтный валидатор для прилетающих айдишников
170
-        if ($this->attributes) foreach ($this->attributes as $fieldName => $fieldParams) {
174
+        if ($this->attributes) {
175
+            foreach ($this->attributes as $fieldName => $fieldParams) {
171 176
             $validator = Validator::createValidator('safe', $owner, ["{$fieldName}_ids"]);
177
+        }
172 178
             $validators->append($validator);
173 179
         }
174 180
     }
@@ -189,8 +195,9 @@  discard block
 block discarded – undo
189 195
      */
190 196
     public function canSetProperty($name, $checkVars = true)
191 197
     {
192
-        if (array_key_exists($this->getRealAttributeName($name), $this->attributes))
193
-            return true;
198
+        if (array_key_exists($this->getRealAttributeName($name), $this->attributes)) {
199
+                    return true;
200
+        }
194 201
 
195 202
         return parent::canSetProperty($name, $checkVars = true);
196 203
     }
@@ -216,8 +223,8 @@  discard block
 block discarded – undo
216 223
                     isset($this->attributes[$att_name]['validator']) &&
217 224
                     isset($this->attributes[$att_name]['validator']['yii\validators\FileValidator']) &&
218 225
                     $this->attributes[$att_name]['validator']['yii\validators\FileValidator']->maxFiles > 1
219
-                )
220
-                    $this->cachedFiles[$att_name] = File::find()
226
+                ) {
227
+                                    $this->cachedFiles[$att_name] = File::find()
221 228
                         ->where(
222 229
                             [
223 230
                                 'object_id' => $this->owner->id,
@@ -226,7 +233,7 @@  discard block
 block discarded – undo
226 233
                             ])
227 234
                         ->orderBy('ordering ASC')
228 235
                         ->all();
229
-                else {
236
+                } else {
230 237
                     $this->cachedFiles[$att_name] = File::find()
231 238
                         ->where(
232 239
                             [
@@ -251,8 +258,9 @@  discard block
 block discarded – undo
251 258
     {
252 259
         $attribute = $this->getRealAttributeName($name);
253 260
 
254
-        if (array_key_exists($attribute, $this->attributes))
255
-            $this->_values[$attribute] = $value;
261
+        if (array_key_exists($attribute, $this->attributes)) {
262
+                    $this->_values[$attribute] = $value;
263
+        }
256 264
     }
257 265
 
258 266
 
Please login to merge, or discard this patch.
src/logic/FileCreateFromPath.php 1 patch
Braces   +27 added lines, -18 removed lines patch added patch discarded remove patch
@@ -29,17 +29,21 @@  discard block
 block discarded – undo
29 29
 
30 30
         $this->model = $model;
31 31
 
32
-        if (!$filePath || !$className || !$fieldName || !$storagePath)
33
-            throw new ErrorException("Empty params not allowed.");
32
+        if (!$filePath || !$className || !$fieldName || !$storagePath) {
33
+                    throw new ErrorException("Empty params not allowed.");
34
+        }
34 35
 
35
-        if (!file_exists($storagePath))
36
-            throw new ErrorException("File storage not found on disk.");
36
+        if (!file_exists($storagePath)) {
37
+                    throw new ErrorException("File storage not found on disk.");
38
+        }
37 39
 
38
-        if (!file_exists($filePath))
39
-            throw new ErrorException("File not found on disk.");
40
+        if (!file_exists($filePath)) {
41
+                    throw new ErrorException("File not found on disk.");
42
+        }
40 43
 
41
-        if (!is_writable($storagePath))
42
-            throw new ErrorException("File storage is not writable.");
44
+        if (!is_writable($storagePath)) {
45
+                    throw new ErrorException("File storage is not writable.");
46
+        }
43 47
         $this->filePath = $filePath;
44 48
         $this->fileName = $fileName;
45 49
         $this->fieldName = $fieldName;
@@ -65,16 +69,19 @@  discard block
 block discarded – undo
65 69
         $this->model->field = $this->fieldName;
66 70
         $this->model->class = $this->className;
67 71
         $this->model->filename = $filename;
68
-        if ($this->model->filename)
69
-            $this->model->title = $this->model->filename;
70
-        else
71
-            $this->model->title = rand(0, 99999); #такой прикол )
72
+        if ($this->model->filename) {
73
+                    $this->model->title = $this->model->filename;
74
+        } else {
75
+                    $this->model->title = rand(0, 99999);
76
+        }
77
+        #такой прикол )
72 78
         $this->model->content_type = $this->model->mime_content_type($new_path);
73 79
         $this->model->type = $this->detectType();
74 80
         $this->model->size = filesize($new_path);
75 81
         $this->model->created = time();
76
-        if ($this->model->type == FileType::VIDEO)
77
-            $this->model->video_status = 0;
82
+        if ($this->model->type == FileType::VIDEO) {
83
+                    $this->model->video_status = 0;
84
+        }
78 85
 
79 86
         if ($this->model->save()) {
80 87
 
@@ -110,10 +117,12 @@  discard block
 block discarded – undo
110 117
     private function detectType()
111 118
     {
112 119
         $contentTypeArray = explode('/', $this->model->content_type);
113
-        if ($contentTypeArray[0] == 'image')
114
-            return FileType::IMAGE;
115
-        if ($contentTypeArray[0] == 'video')
116
-            return FileType::VIDEO;
120
+        if ($contentTypeArray[0] == 'image') {
121
+                    return FileType::IMAGE;
122
+        }
123
+        if ($contentTypeArray[0] == 'video') {
124
+                    return FileType::VIDEO;
125
+        }
117 126
         return FileType::FILE;
118 127
     }
119 128
 }
Please login to merge, or discard this patch.
src/models/File.php 1 patch
Braces   +45 added lines, -30 removed lines patch added patch discarded remove patch
@@ -86,29 +86,37 @@  discard block
 block discarded – undo
86 86
     {
87 87
         $icon = IconHelper::FILE;
88 88
 
89
-        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document')
90
-            $icon = IconHelper::FILE_WORD;
89
+        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.wordprocessingml.document') {
90
+                    $icon = IconHelper::FILE_WORD;
91
+        }
91 92
 
92
-        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')
93
-            $icon = IconHelper::FILE_EXCEL;
93
+        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') {
94
+                    $icon = IconHelper::FILE_EXCEL;
95
+        }
94 96
 
95
-        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation')
96
-            $icon = IconHelper::FILE_POWERPOINT;
97
+        if ($this->content_type == 'application/vnd.openxmlformats-officedocument.presentationml.presentation') {
98
+                    $icon = IconHelper::FILE_POWERPOINT;
99
+        }
97 100
 
98
-        if ($this->content_type == 'application/x-zip-compressed')
99
-            $icon = IconHelper::FILE_ARCHIVE;
101
+        if ($this->content_type == 'application/x-zip-compressed') {
102
+                    $icon = IconHelper::FILE_ARCHIVE;
103
+        }
100 104
 
101
-        if ($this->content_type == 'application/octet-stream')
102
-            $icon = IconHelper::FILE_ARCHIVE;
105
+        if ($this->content_type == 'application/octet-stream') {
106
+                    $icon = IconHelper::FILE_ARCHIVE;
107
+        }
103 108
 
104
-        if (preg_match('/audio/', $this->content_type))
105
-            $icon = IconHelper::FILE_AUDIO;
109
+        if (preg_match('/audio/', $this->content_type)) {
110
+                    $icon = IconHelper::FILE_AUDIO;
111
+        }
106 112
 
107
-        if (preg_match('/pdf/', $this->content_type))
108
-            $icon = IconHelper::FILE_PDF;
113
+        if (preg_match('/pdf/', $this->content_type)) {
114
+                    $icon = IconHelper::FILE_PDF;
115
+        }
109 116
 
110
-        if ($this->type == FileType::VIDEO)
111
-            $icon = IconHelper::FILE_VIDEO;
117
+        if ($this->type == FileType::VIDEO) {
118
+                    $icon = IconHelper::FILE_VIDEO;
119
+        }
112 120
 
113 121
         return $icon;
114 122
     }
@@ -224,8 +232,9 @@  discard block
 block discarded – undo
224 232
 
225 233
     public function getRootPreviewPath()
226 234
     {
227
-        if ($this->isSvg())
228
-            return $this->getRootPath();
235
+        if ($this->isSvg()) {
236
+                    return $this->getRootPath();
237
+        }
229 238
 
230 239
         return Yii::$app->getModule('files')->storageFullPath . DIRECTORY_SEPARATOR . $this->filename . '.jpg';
231 240
     }
@@ -256,8 +265,9 @@  discard block
 block discarded – undo
256 265
 
257 266
     public function getHref()
258 267
     {
259
-        if (Yii::$app->getModule('files')->hostStatic)
260
-            return Yii::$app->getModule('files')->hostStatic . $this->filename;
268
+        if (Yii::$app->getModule('files')->hostStatic) {
269
+                    return Yii::$app->getModule('files')->hostStatic . $this->filename;
270
+        }
261 271
         return Url::to(['/files/default/get', 'hash' => $this->hash]);
262 272
     }
263 273
 
@@ -333,8 +343,9 @@  discard block
 block discarded – undo
333 343
             isset($this->behaviors['files']) &&
334 344
             isset($this->behaviors['files']->attributes[$this->field]) &&
335 345
             isset($this->behaviors['files']->attributes[$this->field]['watermark'])
336
-        )
337
-            $this->behaviors['files']->attributes[$this->field]['watermark'];
346
+        ) {
347
+                    $this->behaviors['files']->attributes[$this->field]['watermark'];
348
+        }
338 349
     }
339 350
 
340 351
     /**
@@ -355,14 +366,17 @@  discard block
 block discarded – undo
355 366
      */
356 367
     public function getPreviewWebPath(int $width = 0, bool $webp = false)
357 368
     {
358
-        if (!file_exists($this->getRootPath()))
359
-            return null;
369
+        if (!file_exists($this->getRootPath())) {
370
+                    return null;
371
+        }
360 372
 
361
-        if (!$this->isVideo() && !$this->isImage())
362
-            throw new \ErrorException('Requiested file is not an image and its implsible to resize it.');
373
+        if (!$this->isVideo() && !$this->isImage()) {
374
+                    throw new \ErrorException('Requiested file is not an image and its implsible to resize it.');
375
+        }
363 376
 
364
-        if (Yii::$app->getModule('files')->hostStatic)
365
-            return Yii::$app->getModule('files')->hostStatic . $this->makeNameWithSize($this->filename, $width, $height, $webp = false);
377
+        if (Yii::$app->getModule('files')->hostStatic) {
378
+                    return Yii::$app->getModule('files')->hostStatic . $this->makeNameWithSize($this->filename, $width, $height, $webp = false);
379
+        }
366 380
 
367 381
         return Url::toRoute(['/files/default/image', 'hash' => $this->hash, 'width' => $width, 'height' => $height, 'webp' => $webp]);
368 382
     }
@@ -406,8 +420,9 @@  discard block
 block discarded – undo
406 420
      */
407 421
     public function getPreviewRootPath($width = 0, $webp = false)
408 422
     {
409
-        if (!$this->isVideo() && !$this->isImage())
410
-            throw new \ErrorException('Requiested file is not an image and its implsible to resize it.');
423
+        if (!$this->isVideo() && !$this->isImage()) {
424
+                    throw new \ErrorException('Requiested file is not an image and its implsible to resize it.');
425
+        }
411 426
         return $this->makeNameWithSize($this->rootPath, $width, $webp);
412 427
     }
413 428
 
Please login to merge, or discard this patch.
src/components/PictureWidget.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,8 +26,9 @@
 block discarded – undo
26 26
      */
27 27
     public function run(): ?string
28 28
     {
29
-        if (!in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO]))
30
-            return null;
29
+        if (!in_array($this->model->type, [FileType::IMAGE, FileType::VIDEO])) {
30
+                    return null;
31
+        }
31 32
         return $this->render('pictureWidget', [
32 33
             'model' => $this->model,
33 34
             'width' => $this->width,
Please login to merge, or discard this patch.
src/components/VideoWidget.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,8 +21,9 @@
 block discarded – undo
21 21
      */
22 22
     public function run(): ?string
23 23
     {
24
-        if ($this->model->type !== FileType::VIDEO)
25
-            return null;
24
+        if ($this->model->type !== FileType::VIDEO) {
25
+                    return null;
26
+        }
26 27
         $source = Html::tag('source', null, ['src' => $this->model->getHref(), 'type' => $this->model->content_type]);
27 28
         return Html::tag('video', $source, $this->options);
28 29
     }
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
@@ -46,14 +46,17 @@  discard block
 block discarded – undo
46 46
     private function loadAndCheckModel(string $hash): void
47 47
     {
48 48
         $this->model = File::findOne(['hash' => $hash]);
49
-        if (!$this->model)
50
-            throw new NotFoundHttpException("Запрашиваемый файл не найден");
49
+        if (!$this->model) {
50
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден");
51
+        }
51 52
 
52
-        if (!$this->model->isImage() && !$this->model->isVideo())
53
-            throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
53
+        if (!$this->model->isImage() && !$this->model->isVideo()) {
54
+                    throw new NotFoundHttpException("Запрашиваемый файл не является изображением");
55
+        }
54 56
 
55
-        if (!file_exists($this->model->rootPath))
56
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
57
+        if (!file_exists($this->model->rootPath)) {
58
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
59
+        }
57 60
     }
58 61
 
59 62
     /**
@@ -65,8 +68,9 @@  discard block
 block discarded – undo
65 68
     {
66 69
         $filename = Yii::createObject(ImagePreviewer::class, [$this->model, $width, $webp])->getUrl();
67 70
 
68
-        if (!file_exists($filename))
69
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
71
+        if (!file_exists($filename)) {
72
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
73
+        }
70 74
 
71 75
         $response = Yii::$app->response;
72 76
         $response->format = Response::FORMAT_RAW;
Please login to merge, or discard this patch.
src/actions/GetFileAction.php 1 patch
Braces   +6 added lines, -4 removed lines patch added patch discarded remove patch
@@ -14,11 +14,13 @@
 block discarded – undo
14 14
     {
15 15
         $model = File::findOne(['hash' => $hash]);
16 16
 
17
-        if (!$model)
18
-            throw new NotFoundHttpException("Запрашиваемый файл не найден");
17
+        if (!$model) {
18
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден");
19
+        }
19 20
 
20
-        if (!file_exists($model->rootPath))
21
-            throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
21
+        if (!file_exists($model->rootPath)) {
22
+                    throw new NotFoundHttpException('Запрашиваемый файл не найден на диске.');
23
+        }
22 24
 
23 25
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
24 26
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
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
@@ -72,8 +72,9 @@  discard block
 block discarded – undo
72 72
      */
73 73
     private function checkFormToken()
74 74
     {
75
-        if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken'))
76
-            throw new BadRequestHttpException('File-form token is wrong or missing.');
75
+        if (in_array($this->action->id, $this->actionsToCheck) && FileInputWidget::generateToken() != Yii::$app->request->post('_fileFormToken')) {
76
+                    throw new BadRequestHttpException('File-form token is wrong or missing.');
77
+        }
77 78
     }
78 79
 
79 80
     /**
@@ -86,12 +87,14 @@  discard block
 block discarded – undo
86 87
 
87 88
         $zip = new  ZipArchive;
88 89
         $filename = Yii::getAlias("@webroot/assets/files.zip");
89
-        if (file_exists($filename))
90
-            @unlink($filename);
90
+        if (file_exists($filename)) {
91
+                    @unlink($filename);
92
+        }
91 93
         if (sizeof($files) && $zip->open($filename, ZipArchive::CREATE)) {
92 94
 
93
-            foreach ($files as $file)
94
-                $zip->addFile($file->rootPath, $file->title);
95
+            foreach ($files as $file) {
96
+                            $zip->addFile($file->rootPath, $file->title);
97
+            }
95 98
 
96 99
             $zip->close();
97 100
             header("Pragma: public");
@@ -163,8 +166,9 @@  discard block
 block discarded – undo
163 166
 
164 167
         $view = Yii::$app->request->post('mode') == 'single' ? "_single" : "_file";
165 168
 
166
-        if ($ratio)
167
-            $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
169
+        if ($ratio) {
170
+                    $this->getView()->registerJs("initCropper({$model->id}, '{$model->href}', {$ratio}, true);");
171
+        }
168 172
 
169 173
         return $this->renderAjax($view, [
170 174
             'model' => $model,
@@ -190,8 +194,9 @@  discard block
 block discarded – undo
190 194
     {
191 195
         $model = File::findOne(['hash' => $hash]);
192 196
 
193
-        if (!$model)
194
-            throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
197
+        if (!$model) {
198
+                    throw new NotFoundHttpException("Запрашиваемый файл не найден в базе.");
199
+        }
195 200
 
196 201
         $response = Yii::$app->response;
197 202
         $response->format = Response::FORMAT_RAW;
@@ -200,8 +205,9 @@  discard block
 block discarded – undo
200 205
         Yii::$app->response->headers->set('Last-Modified', date("c", $model->created));
201 206
         Yii::$app->response->headers->set('Cache-Control', 'public, max-age=' . (60 * 60 * 24 * 15));
202 207
 
203
-        if (!file_exists($model->rootPreviewPath))
204
-            throw new NotFoundHttpException('Preview not found.');
208
+        if (!file_exists($model->rootPreviewPath)) {
209
+                    throw new NotFoundHttpException('Preview not found.');
210
+        }
205 211
 
206 212
         $response->sendFile($model->rootPreviewPath, 'preview.jpg');
207 213
 
Please login to merge, or discard this patch.
src/logic/VideoFrameExtractor.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -18,14 +18,17 @@  discard block
 block discarded – undo
18 18
     {
19 19
         $this->ffmpegBin = Yii::$app->getModule('files')->ffmpeg;
20 20
 
21
-        if (!file_exists($this->ffmpegBin))
22
-            throw new \ErrorException("ffmpeg is not found: {$this->ffmpegBin}");
21
+        if (!file_exists($this->ffmpegBin)) {
22
+                    throw new \ErrorException("ffmpeg is not found: {$this->ffmpegBin}");
23
+        }
23 24
 
24
-        if (!is_executable($this->ffmpegBin))
25
-            throw new \ErrorException("ffmpeg is not executable: {$this->ffmpegBin}");
25
+        if (!is_executable($this->ffmpegBin)) {
26
+                    throw new \ErrorException("ffmpeg is not executable: {$this->ffmpegBin}");
27
+        }
26 28
 
27
-        if (!is_file($videoSourceFilename))
28
-            throw new \ErrorException('File not found on disk.');
29
+        if (!is_file($videoSourceFilename)) {
30
+                    throw new \ErrorException('File not found on disk.');
31
+        }
29 32
 
30 33
         $this->videoSourceFilename = $videoSourceFilename;
31 34
         $this->outputImageFilename = $outputImageFilename;
@@ -38,8 +41,9 @@  discard block
 block discarded – undo
38 41
     {
39 42
         $command = "{$this->ffmpegBin} -i {$this->videoSourceFilename}  -ss 00:00:03.000 -vframes 1  {$this->outputImageFilename}";
40 43
         exec($command, $out, $result);
41
-        if ($result !== 0)
42
-            throw new \ErrorException('FFmpeg frame extracting fail:' . print_r($out, true));
44
+        if ($result !== 0) {
45
+                    throw new \ErrorException('FFmpeg frame extracting fail:' . print_r($out, true));
46
+        }
43 47
     }
44 48
 
45 49
 }
Please login to merge, or discard this patch.