Completed
Push — master ( 5e90e6...c5eccd )
by Evgenii
03:04
created
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.