Completed
Push — tests ( bf6e7f...77e6ac )
by Alimzhan
31:02 queued 28:44
created
src/behaviors/FileBehavior.php 2 patches
Unused Use Statements   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -8,8 +8,8 @@
 block discarded – undo
8 8
 
9 9
 namespace nemmo\attachments\behaviors;
10 10
 
11
-use nemmo\attachments\models\File;
12 11
 use nemmo\attachments\ModuleTrait;
12
+use nemmo\attachments\models\File;
13 13
 use yii\base\Behavior;
14 14
 use yii\db\ActiveRecord;
15 15
 use yii\helpers\FileHelper;
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
 
37 37
         if (!empty($files)) {
38 38
             foreach ($files as $file) {
39
-                if (!$file->saveAs($this->getModule()->getUserDirPath() . $file->name)) {
39
+                if (!$file->saveAs($this->getModule()->getUserDirPath().$file->name)) {
40 40
                     throw new \Exception(\Yii::t('yii', 'File upload failed.'));
41 41
                 }
42 42
             }
@@ -83,10 +83,10 @@  discard block
 block discarded – undo
83 83
             if (substr(FileHelper::getMimeType($file), 0, 5) === 'image') {
84 84
                 $initialPreview[] = Html::img(['/attachments/file/download-temp', 'filename' => basename($file)], ['class' => 'file-preview-image']);
85 85
             } else {
86
-                $initialPreview[] = Html::beginTag('div', ['class' => 'file-preview-other']) .
87
-                    Html::beginTag('h2') .
88
-                    Html::tag('i', '', ['class' => 'glyphicon glyphicon-file']) .
89
-                    Html::endTag('h2') .
86
+                $initialPreview[] = Html::beginTag('div', ['class' => 'file-preview-other']).
87
+                    Html::beginTag('h2').
88
+                    Html::tag('i', '', ['class' => 'glyphicon glyphicon-file']).
89
+                    Html::endTag('h2').
90 90
                     Html::endTag('div');
91 91
             }
92 92
         }
@@ -95,10 +95,10 @@  discard block
 block discarded – undo
95 95
             if (substr($file->mime, 0, 5) === 'image') {
96 96
                 $initialPreview[] = Html::img($file->getUrl(), ['class' => 'file-preview-image']);
97 97
             } else {
98
-                $initialPreview[] = Html::beginTag('div', ['class' => 'file-preview-other']) .
99
-                    Html::beginTag('h2') .
100
-                    Html::tag('i', '', ['class' => 'glyphicon glyphicon-file']) .
101
-                    Html::endTag('h2') .
98
+                $initialPreview[] = Html::beginTag('div', ['class' => 'file-preview-other']).
99
+                    Html::beginTag('h2').
100
+                    Html::tag('i', '', ['class' => 'glyphicon glyphicon-file']).
101
+                    Html::endTag('h2').
102 102
                     Html::endTag('div');
103 103
             }
104 104
         }
Please login to merge, or discard this patch.
src/components/AttachmentsTable.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,9 +2,9 @@
 block discarded – undo
2 2
 
3 3
 namespace nemmo\attachments\components;
4 4
 
5
-use nemmo\attachments\behaviors\FileBehavior;
6
-use nemmo\attachments\ModuleTrait;
7 5
 use Yii;
6
+use nemmo\attachments\ModuleTrait;
7
+use nemmo\attachments\behaviors\FileBehavior;
8 8
 use yii\bootstrap\Widget;
9 9
 use yii\data\ArrayDataProvider;
10 10
 use yii\db\ActiveRecord;
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
                 [
75 75
                     'label' => $this->getModule()->t('attachments', 'File name'),
76 76
                     'format' => 'raw',
77
-                    'value' => function ($model) {
77
+                    'value' => function($model) {
78 78
                         return Html::a("$model->name.$model->type", $model->getUrl());
79 79
                     }
80 80
                 ],
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                     'class' => 'yii\grid\ActionColumn',
83 83
                     'template' => '{delete}',
84 84
                     'buttons' => [
85
-                        'delete' => function ($url, $model, $key) {
85
+                        'delete' => function($url, $model, $key) {
86 86
                             return Html::a('<span class="glyphicon glyphicon-trash"></span>',
87 87
                                 [
88 88
                                     '/attachments/file/delete',
Please login to merge, or discard this patch.
src/components/AttachmentsTableWithPreview.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@
 block discarded – undo
2 2
 
3 3
 namespace nemmo\attachments\components;
4 4
 
5
+use Yii;
5 6
 use himiklab\colorbox\Colorbox;
6
-use nemmo\attachments\behaviors\FileBehavior;
7 7
 use nemmo\attachments\ModuleTrait;
8
-use Yii;
8
+use nemmo\attachments\behaviors\FileBehavior;
9 9
 use yii\bootstrap\Widget;
10 10
 use yii\data\ArrayDataProvider;
11 11
 use yii\db\ActiveRecord;
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
         if (!$this->model) {
39 39
             return Html::tag('div',
40 40
                 Html::tag('b',
41
-                    Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The model cannot be empty.'
41
+                    Yii::t('yii', 'Error')).': '.$this->getModule()->t('attachments', 'The model cannot be empty.'
42 42
                 ),
43 43
                 [
44 44
                     'class' => 'alert alert-danger'
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
         if (!$hasFileBehavior) {
56 56
             return Html::tag('div',
57 57
                 Html::tag('b',
58
-                    Yii::t('yii', 'Error')) . ': ' . $this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'
58
+                    Yii::t('yii', 'Error')).': '.$this->getModule()->t('attachments', 'The behavior FileBehavior has not been attached to the model.'
59 59
                 ),
60 60
                 [
61 61
                     'class' => 'alert alert-danger'
@@ -75,9 +75,9 @@  discard block
 block discarded – undo
75 75
                 [
76 76
                     'label' => $this->getModule()->t('attachments', 'File name'),
77 77
                     'format' => 'raw',
78
-                    'value' => function ($model) {
78
+                    'value' => function($model) {
79 79
                         return Html::a("$model->name.$model->type", $model->getUrl(), [
80
-                            'class' => ' group' . $model->itemId,
80
+                            'class' => ' group'.$model->itemId,
81 81
                             'onclick' => 'return false;',
82 82
                         ]);
83 83
                     }
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
                     'class' => 'yii\grid\ActionColumn',
87 87
                     'template' => '{delete}',
88 88
                     'buttons' => [
89
-                        'delete' => function ($url, $model, $key) {
89
+                        'delete' => function($url, $model, $key) {
90 90
                             return Html::a('<span class="glyphicon glyphicon-trash"></span>',
91 91
                                 [
92 92
                                     '/attachments/file/delete',
@@ -102,11 +102,11 @@  discard block
 block discarded – undo
102 102
                     ]
103 103
                 ],
104 104
             ],
105
-        ]) .
105
+        ]).
106 106
         Colorbox::widget([
107 107
             'targets' => [
108
-                '.group' . $this->model->id => [
109
-                    'rel' => '.group' . $this->model->id,
108
+                '.group'.$this->model->id => [
109
+                    'rel' => '.group'.$this->model->id,
110 110
                     'photo' => true,
111 111
                     'scalePhotos' => true,
112 112
                     'width' => '100%',
Please login to merge, or discard this patch.
src/Module.php 3 patches
Doc Comments   +5 added lines, -1 removed lines patch added patch discarded remove patch
@@ -44,6 +44,10 @@  discard block
 block discarded – undo
44 44
         ];
45 45
     }
46 46
 
47
+    /**
48
+     * @param string $category
49
+     * @param string $message
50
+     */
47 51
     public static function t($category, $message, $params = [], $language = null)
48 52
     {
49 53
         return \Yii::t('nemmo/' . $category, $message, $params, $language);
@@ -109,7 +113,7 @@  discard block
 block discarded – undo
109 113
 
110 114
     /**
111 115
      * @param $filePath string
112
-     * @param $owner
116
+     * @param \yii\base\Component $owner
113 117
      * @return bool|File
114 118
      * @throws \Exception
115 119
      * @throws \yii\base\InvalidConfigException
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -81,7 +81,9 @@  discard block
 block discarded – undo
81 81
         for ($i = 0; $i < $depth; $i++) {
82 82
             $folder = substr($fileHash, $i * 3, 2);
83 83
             $path .= $folder;
84
-            if ($i != $depth - 1) $path .= DIRECTORY_SEPARATOR;
84
+            if ($i != $depth - 1) {
85
+                $path .= DIRECTORY_SEPARATOR;
86
+            }
85 87
         }
86 88
 
87 89
         return $path;
@@ -167,7 +169,9 @@  discard block
 block discarded – undo
167 169
     {
168 170
         /** @var File $file */
169 171
         $file = File::findOne(['id' => $id]);
170
-        if (empty($file)) return false;
172
+        if (empty($file)) {
173
+            return false;
174
+        }
171 175
         $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
172 176
 
173 177
         return unlink($filePath) && $file->delete();
Please login to merge, or discard this patch.
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
     public static function t($category, $message, $params = [], $language = null)
49 49
     {
50
-        return \Yii::t('nemmo/' . $category, $message, $params, $language);
50
+        return \Yii::t('nemmo/'.$category, $message, $params, $language);
51 51
     }
52 52
 
53 53
     public function getStorePath()
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
      */
67 67
     public function getFilesDirPath($fileHash)
68 68
     {
69
-        $path = $this->getStorePath() . DIRECTORY_SEPARATOR . $this->getSubDirs($fileHash);
69
+        $path = $this->getStorePath().DIRECTORY_SEPARATOR.$this->getSubDirs($fileHash);
70 70
 
71 71
         FileHelper::createDirectory($path);
72 72
 
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
     {
92 92
         \Yii::$app->session->open();
93 93
 
94
-        $userDirPath = $this->getTempPath() . DIRECTORY_SEPARATOR . \Yii::$app->session->id;
94
+        $userDirPath = $this->getTempPath().DIRECTORY_SEPARATOR.\Yii::$app->session->id;
95 95
         FileHelper::createDirectory($userDirPath);
96 96
 
97 97
         \Yii::$app->session->close();
98 98
 
99
-        return $userDirPath . DIRECTORY_SEPARATOR;
99
+        return $userDirPath.DIRECTORY_SEPARATOR;
100 100
     }
101 101
 
102 102
     public function getShortClass($obj)
@@ -124,11 +124,11 @@  discard block
 block discarded – undo
124 124
             throw new Exception("File $filePath not exists");
125 125
         }
126 126
 
127
-        $fileHash = md5(microtime(true) . $filePath);
127
+        $fileHash = md5(microtime(true).$filePath);
128 128
         $fileType = pathinfo($filePath, PATHINFO_EXTENSION);
129 129
         $newFileName = "$fileHash.$fileType";
130 130
         $fileDirPath = $this->getFilesDirPath($fileHash);
131
-        $newFilePath = $fileDirPath . DIRECTORY_SEPARATOR . $newFileName;
131
+        $newFilePath = $fileDirPath.DIRECTORY_SEPARATOR.$newFileName;
132 132
 
133 133
         if (!copy($filePath, $newFilePath)) {
134 134
             throw new Exception("Cannot copy file! $filePath  to $newFilePath");
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
         /** @var File $file */
157 157
         $file = File::findOne(['id' => $id]);
158 158
         if (empty($file)) return false;
159
-        $filePath = $this->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
159
+        $filePath = $this->getFilesDirPath($file->hash).DIRECTORY_SEPARATOR.$file->hash.'.'.$file->type;
160 160
 
161 161
         return unlink($filePath) && $file->delete();
162 162
     }
Please login to merge, or discard this patch.
src/controllers/FileController.php 2 patches
Unused Use Statements   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -2,10 +2,10 @@
 block discarded – undo
2 2
 
3 3
 namespace nemmo\attachments\controllers;
4 4
 
5
+use Yii;
6
+use nemmo\attachments\ModuleTrait;
5 7
 use nemmo\attachments\models\File;
6 8
 use nemmo\attachments\models\UploadForm;
7
-use nemmo\attachments\ModuleTrait;
8
-use Yii;
9 9
 use yii\helpers\FileHelper;
10 10
 use yii\helpers\Url;
11 11
 use yii\web\Controller;
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@  discard block
 block discarded – undo
28 28
             $result['uploadedFiles'] = [];
29 29
             if (is_array($model->file)) {
30 30
                 foreach ($model->file as $file) {
31
-                    $path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $file->name;
31
+                    $path = $this->getModule()->getUserDirPath().DIRECTORY_SEPARATOR.$file->name;
32 32
                     $file->saveAs($path);
33 33
                     $result['uploadedFiles'][] = $file->name;
34 34
                 }
35 35
             } else {
36
-                $path = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $model->file->name;
36
+                $path = $this->getModule()->getUserDirPath().DIRECTORY_SEPARATOR.$model->file->name;
37 37
                 $model->file->saveAs($path);
38 38
                 $result['uploadedFiles'][] = $model->file->name;
39 39
             }
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     public function actionDownload($id)
51 51
     {
52 52
         $file = File::findOne(['id' => $id]);
53
-        $filePath = $this->getModule()->getFilesDirPath($file->hash) . DIRECTORY_SEPARATOR . $file->hash . '.' . $file->type;
53
+        $filePath = $this->getModule()->getFilesDirPath($file->hash).DIRECTORY_SEPARATOR.$file->hash.'.'.$file->type;
54 54
 
55 55
         return Yii::$app->response->sendFile($filePath, "$file->name.$file->type");
56 56
     }
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 
67 67
     public function actionDownloadTemp($filename)
68 68
     {
69
-        $filePath = $this->getModule()->getUserDirPath() . DIRECTORY_SEPARATOR . $filename;
69
+        $filePath = $this->getModule()->getUserDirPath().DIRECTORY_SEPARATOR.$filename;
70 70
 
71 71
         return Yii::$app->response->sendFile($filePath, $filename);
72 72
     }
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
     public function actionDeleteTemp($filename)
75 75
     {
76 76
         $userTempDir = $this->getModule()->getUserDirPath();
77
-        $filePath = $userTempDir . DIRECTORY_SEPARATOR . $filename;
77
+        $filePath = $userTempDir.DIRECTORY_SEPARATOR.$filename;
78 78
         unlink($filePath);
79 79
         if (!sizeof(FileHelper::findFiles($userTempDir))) {
80 80
             rmdir($userTempDir);
Please login to merge, or discard this patch.
src/migrations/m150127_040544_add_attachments.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -11,13 +11,13 @@
 block discarded – undo
11 11
     {
12 12
         $this->createTable($this->getModule()->tableName, [
13 13
             'id' => Schema::TYPE_PK,
14
-            'name' => Schema::TYPE_STRING . ' not null',
15
-            'model' => Schema::TYPE_STRING . ' not null',
16
-            'itemId' => Schema::TYPE_INTEGER . ' not null',
17
-            'hash' => Schema::TYPE_STRING . ' not null',
18
-            'size' => Schema::TYPE_INTEGER . ' not null',
19
-            'type' => Schema::TYPE_STRING . ' not null',
20
-            'mime' => Schema::TYPE_STRING . ' not null'
14
+            'name' => Schema::TYPE_STRING.' not null',
15
+            'model' => Schema::TYPE_STRING.' not null',
16
+            'itemId' => Schema::TYPE_INTEGER.' not null',
17
+            'hash' => Schema::TYPE_STRING.' not null',
18
+            'size' => Schema::TYPE_INTEGER.' not null',
19
+            'type' => Schema::TYPE_STRING.' not null',
20
+            'mime' => Schema::TYPE_STRING.' not null'
21 21
         ]);
22 22
 
23 23
         $this->createIndex('file_model', $this->getModule()->tableName, 'model');
Please login to merge, or discard this patch.
src/models/File.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,6 +67,6 @@
 block discarded – undo
67 67
 
68 68
     public function getPath()
69 69
     {
70
-        return $this->getModule()->getFilesDirPath($this->hash) . DIRECTORY_SEPARATOR . $this->hash . '.' . $this->type;
70
+        return $this->getModule()->getFilesDirPath($this->hash).DIRECTORY_SEPARATOR.$this->hash.'.'.$this->type;
71 71
     }
72 72
 }
Please login to merge, or discard this patch.