Completed
Push — master ( 50a99d...aba1e6 )
by Evgenii
02:53
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,8 +41,9 @@  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 . DIRECTORY_SEPARATOR . $this->model->makeNameWithSize($this->model->filename,
47 49
                 $this->width, 0);
@@ -50,14 +52,17 @@  discard block
 block discarded – undo
50 52
 
51 53
         $this->prepareFolder();
52 54
 
53
-        if (!file_exists($this->fileName) || filesize($this->fileName) == 0)
54
-            $this->createPreview();
55
+        if (!file_exists($this->fileName) || filesize($this->fileName) == 0) {
56
+                    $this->createPreview();
57
+        }
55 58
 
56
-        if ($this->webp && !file_exists($this->fileNameWebp))
57
-            $this->createPreviewWebp();
59
+        if ($this->webp && !file_exists($this->fileNameWebp)) {
60
+                    $this->createPreviewWebp();
61
+        }
58 62
 
59
-        if ($this->webp)
60
-            return $this->fileNameWebp;
63
+        if ($this->webp) {
64
+                    return $this->fileNameWebp;
65
+        }
61 66
 
62 67
         return $this->fileName;
63 68
     }
@@ -96,20 +101,24 @@  discard block
 block discarded – undo
96 101
      */
97 102
     protected function prepareFolder()
98 103
     {
99
-        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath))
100
-            mkdir(Yii::$app->getModule('files')->cacheFullPath);
104
+        if (!file_exists(Yii::$app->getModule('files')->cacheFullPath)) {
105
+                    mkdir(Yii::$app->getModule('files')->cacheFullPath);
106
+        }
101 107
         $folders = [];
102 108
         $lastFolder = '/';
103 109
         $explodes = explode('/', $this->fileName);
104 110
         array_pop($explodes);
105
-        if (empty($explodes))
106
-            return;
111
+        if (empty($explodes)) {
112
+                    return;
113
+        }
107 114
         foreach ($explodes as $folder) {
108
-            if (empty($folder))
109
-                continue;
115
+            if (empty($folder)) {
116
+                            continue;
117
+            }
110 118
             $lastFolder = $lastFolder . $folder . '/';
111
-            if (!file_exists($lastFolder))
112
-                mkdir($lastFolder);
119
+            if (!file_exists($lastFolder)) {
120
+                            mkdir($lastFolder);
121
+            }
113 122
             $folders[] = $lastFolder;
114 123
         }
115 124
     }
Please login to merge, or discard this patch.