Passed
Push — master ( 7e2cb5...a0f233 )
by Evgenii
02:58
created
src/components/SimpleImage.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -118,8 +118,9 @@
 block discarded – undo
118 118
     function rotate($direction)
119 119
     {
120 120
         $degrees = 90;
121
-        if ($direction == 2)
122
-            $degrees = 270;
121
+        if ($direction == 2) {
122
+                    $degrees = 270;
123
+        }
123 124
         $this->image = imagerotate($this->image, $degrees, 0);
124 125
     }
125 126
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -25,10 +25,10 @@
 block discarded – undo
25 25
             $this->image = imagecreatefromjpeg($filename);
26 26
         } elseif ($this->image_type == IMAGETYPE_GIF) {
27 27
             $this->image = imagecreatefromgif($filename);
28
-            imageSaveAlpha($this->image,true);
28
+            imageSaveAlpha($this->image, true);
29 29
         } elseif ($this->image_type == IMAGETYPE_PNG) {
30 30
             $this->image = imagecreatefrompng($filename);
31
-            imageSaveAlpha($this->image,true);
31
+            imageSaveAlpha($this->image, true);
32 32
         } elseif ($this->image_type == IMAGETYPE_WEBP) {
33 33
             $this->image = imagecreatefromwebp($filename);
34 34
         }
Please login to merge, or discard this patch.
src/logic/FileRename.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -27,18 +27,21 @@  discard block
 block discarded – undo
27 27
     public function __construct(array $data)
28 28
     {
29 29
 
30
-        if (!isset($data['id']))
31
-            throw new BadRequestHttpException('ID of file is not set.');
30
+        if (!isset($data['id'])) {
31
+                    throw new BadRequestHttpException('ID of file is not set.');
32
+        }
32 33
 
33
-        if (!isset($data['title']))
34
-            throw new BadRequestHttpException('Title of file is not set.');
34
+        if (!isset($data['title'])) {
35
+                    throw new BadRequestHttpException('Title of file is not set.');
36
+        }
35 37
 
36 38
         $this->_title = $data['title'];
37 39
 
38 40
         $this->_file = File::findOne($data['id']);
39 41
 
40
-        if (!$this->_file)
41
-            throw new NotFoundHttpException('File not found.');
42
+        if (!$this->_file) {
43
+                    throw new NotFoundHttpException('File not found.');
44
+        }
42 45
 
43 46
     }
44 47
 
@@ -50,8 +53,9 @@  discard block
 block discarded – undo
50 53
     {
51 54
         $this->_file->title = $this->_title;
52 55
 
53
-        if (!$this->_file->save())
54
-            throw new BadRequestHttpException('Unable to save file.');
56
+        if (!$this->_file->save()) {
57
+                    throw new BadRequestHttpException('Unable to save file.');
58
+        }
55 59
 
56 60
         return $this->_title;
57 61
     }
Please login to merge, or discard this patch.
src/logic/FileCropRotate.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -30,14 +30,17 @@  discard block
 block discarded – undo
30 30
     {
31 31
         $this->_file = File::findOne($data['id']);
32 32
 
33
-        if (!$this->_file)
34
-            throw new NotFoundHttpException('File not found');
33
+        if (!$this->_file) {
34
+                    throw new NotFoundHttpException('File not found');
35
+        }
35 36
 
36
-        if ($this->_file->type != FileType::IMAGE)
37
-            throw new BadRequestHttpException('Requested file is not an image.');
37
+        if ($this->_file->type != FileType::IMAGE) {
38
+                    throw new BadRequestHttpException('Requested file is not an image.');
39
+        }
38 40
 
39
-        if (!file_exists($this->_file->rootPath))
40
-            throw new BadRequestHttpException('File not found in file storage.');
41
+        if (!file_exists($this->_file->rootPath)) {
42
+                    throw new BadRequestHttpException('File not found in file storage.');
43
+        }
41 44
 
42 45
         $this->_height = (int)$data['height'];
43 46
         $this->_width = (int)$data['width'];
@@ -79,8 +82,9 @@  discard block
 block discarded – undo
79 82
         if ($this->_file->save()) {
80 83
             @unlink($oldPath);
81 84
             return $this->_file->href;
82
-        } else
83
-            throw new ErrorException("Error while saving file model.");
85
+        } else {
86
+                    throw new ErrorException("Error while saving file model.");
87
+        }
84 88
 
85 89
 
86 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/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'])->andWhere(['<', '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.
src/logic/FileResize.php 1 patch
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -33,11 +33,13 @@  discard block
 block discarded – undo
33 33
     {
34 34
         $this->_file = $file;
35 35
 
36
-        if ($this->_file->type != FileType::IMAGE)
37
-            throw new ErrorException('This file is not an image.');
36
+        if ($this->_file->type != FileType::IMAGE) {
37
+                    throw new ErrorException('This file is not an image.');
38
+        }
38 39
 
39
-        if (!file_exists($this->_file->rootPath))
40
-            throw new ErrorException('File not found on disk');
40
+        if (!file_exists($this->_file->rootPath)) {
41
+                    throw new ErrorException('File not found on disk');
42
+        }
41 43
 
42 44
         $this->_maxHeight = $maxHeight;
43 45
         $this->_maxWidth = $maxWidth;
@@ -51,16 +53,18 @@  discard block
 block discarded – undo
51 53
      */
52 54
     public function execute(): bool
53 55
     {
54
-        if ($this->_file->content_type == 'image/svg+xml')
55
-            return true;
56
+        if ($this->_file->content_type == 'image/svg+xml') {
57
+                    return true;
58
+        }
56 59
 
57 60
         $image = new SimpleImage();
58 61
         $image->load($this->_file->rootPath);
59 62
 
60 63
         if ($image->getWidth() > $this->_maxWidth || $image->getHeight() > $this->_maxHeight) {
61 64
             $image->resizeToWidth($this->_maxWidth);
62
-            if ($this->_file->content_type == 'image/png')
63
-                $this->_imageType = IMAGETYPE_PNG;
65
+            if ($this->_file->content_type == 'image/png') {
66
+                            $this->_imageType = IMAGETYPE_PNG;
67
+            }
64 68
             $image->save($this->_file->rootPath, $this->_imageType, $this->_compression);
65 69
             $this->_file->size = filesize($this->_file->rootPath);
66 70
             return $this->_file->save(false, ['size']);
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/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.