Passed
Branch master (be549e)
by Saeid
08:15
created
src/MediaServiceProvider.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -14,7 +14,7 @@
 block discarded – undo
14 14
     public function boot()
15 15
     {
16 16
         $this->loadRoutesFrom(__DIR__.'/routes/web.php');
17
-        $this->loadMigrationsFrom(__DIR__ . '/database/migrations');
17
+        $this->loadMigrationsFrom(__DIR__.'/database/migrations');
18 18
         $this->loadViewsFrom(__DIR__.'/resources/views', 'media');
19 19
         $this->mergeConfigFrom(
20 20
             __DIR__.'/config/media.php', 'media'
Please login to merge, or discard this patch.
src/Http/Controllers/MediaController.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,6 +18,6 @@
 block discarded – undo
18 18
         $medium = Medium::create([
19 19
             'file' => $request->file('photo'),
20 20
         ]);
21
-        return back()->with('url' , $medium->url('sm'));
21
+        return back()->with('url', $medium->url('sm'));
22 22
     }
23 23
 }
Please login to merge, or discard this patch.
src/database/migrations/2019_01_22_083452_create_media_table.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,13 +13,13 @@  discard block
 block discarded – undo
13 13
      */
14 14
     public function up()
15 15
     {
16
-        Schema::create('media', function (Blueprint $table) {
16
+        Schema::create('media', function(Blueprint $table) {
17 17
             $table->increments('id');
18 18
             $table->string('stored_name');
19 19
             $table->string('file_name');
20
-            $table->string('extension',5);
20
+            $table->string('extension', 5);
21 21
             $table->string('caption')->nullable();
22
-            $table->string('mime',30);
22
+            $table->string('mime', 30);
23 23
             $table->integer('size');
24 24
             $table->integer('width')->nullable();
25 25
             $table->integer('height')->nullable();
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
             $table->string('manner')->nullable();
30 30
             $table->integer('comments_count')->default(0);
31 31
             $table->integer('likes_count')->default(0);
32
-            $table->string('description',500)->nullable();
32
+            $table->string('description', 500)->nullable();
33 33
             $table->timestamps();
34 34
         });
35 35
     }
Please login to merge, or discard this patch.
src/config/media.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
18 18
      *  Responsive image sizes
19 19
      */
20 20
 
21
-    'LARGE_IMAGE_SIZE'      => 0,   //determine that the image store in original size
21
+    'LARGE_IMAGE_SIZE'      => 0, //determine that the image store in original size
22 22
     'MEDIUM_IMAGE_SIZE'     => 540, // It will save the image in 540x540 pixels
23 23
     'SMALL_IMAGE_SIZE'      => 270, // It will save the image in 270x270 pixels
24 24
     'EXTRA_SMALL_IMAGE_SIZE'=> 135, // It will save the image in 135x135 pixels
Please login to merge, or discard this patch.
src/Medium.php 2 patches
Spacing   +36 added lines, -36 removed lines patch added patch discarded remove patch
@@ -12,24 +12,24 @@  discard block
 block discarded – undo
12 12
 class Medium extends Model
13 13
 {
14 14
     //use Favorite;
15
-    protected $guarded = ['id','file'];
15
+    protected $guarded = ['id', 'file'];
16 16
     public $file_object;
17 17
 
18
-    public function mediumable(){
18
+    public function mediumable() {
19 19
         return $this->morphTo();
20 20
     }
21 21
 
22 22
     public function __construct(array $attributes = [])
23 23
     {
24 24
         parent::__construct($attributes);
25
-        if(isset($attributes['file'])){
25
+        if (isset($attributes['file'])) {
26 26
             $this->attach_file($attributes['file']);
27 27
         }
28 28
     }
29 29
 
30
-    protected function set_up_upload_folders(){
30
+    protected function set_up_upload_folders() {
31 31
 
32
-        if($this->is('image')){
32
+        if ($this->is('image')) {
33 33
             $large_image_folder = storage_path('app/'.$this->full_path_lg);
34 34
             $medium_image_folder = storage_path('app/'.$this->full_path_md);
35 35
             $small_image_folder = storage_path('app/'.$this->full_path_sm);
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             File::isDirectory($medium_image_folder) or File::makeDirectory($medium_image_folder, 0777, true, true);
40 40
             File::isDirectory($small_image_folder) or File::makeDirectory($small_image_folder, 0777, true, true);
41 41
             File::isDirectory($extra_small_image_folder) or File::makeDirectory($extra_small_image_folder, 0777, true, true);
42
-        }else{
42
+        }else {
43 43
             $path = storage_path('app/'.$this->main_upload_folder."/{$this->type}s/");
44 44
             File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
45 45
         }
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 
48 48
     public function attach_file($file)
49 49
     {
50
-        if($this->id){ // if the file already stored
50
+        if ($this->id) { // if the file already stored
51 51
             return false;
52 52
         }
53 53
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
 
69 69
     public function detach()
70 70
     {
71
-        if(!$this->id){
71
+        if (!$this->id) {
72 72
             unset($this->file_object);
73 73
             unset($this->stored_name);
74 74
             unset($this->file_name);
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
             unset($this->width);
79 79
             unset($this->height);
80 80
             return true;
81
-        }else{
81
+        }else {
82 82
             return false;
83 83
         }
84 84
     }
@@ -90,23 +90,23 @@  discard block
 block discarded – undo
90 90
     }
91 91
 
92 92
     public function store() {
93
-        if(!$this->file_object){
93
+        if (!$this->file_object) {
94 94
             throw new Exception('No File Attached');
95 95
         }
96 96
         // Create upload folder if not exists
97 97
         $this->set_up_upload_folders();
98 98
         $stored_name = $this->store_file_name_hashed() ? $this->file_object->hashName() : $this->full_name;
99 99
 
100
-        if($this->is('image')){
101
-            if(config('media.LARGE_IMAGE_SIZE')){
100
+        if ($this->is('image')) {
101
+            if (config('media.LARGE_IMAGE_SIZE')) {
102 102
                 Image::make($this->file_object)
103 103
                     ->widen(config('media.LARGE_IMAGE_SIZE'))
104 104
                     ->save(storage_path('app/'.$this->full_path_lg.'/'.$stored_name));
105
-            }else{
105
+            }else {
106 106
                 $this->file_object->storeAs($this->full_path_lg, $stored_name);
107 107
             }
108 108
 
109
-            if(config('media.CREATE_RESPONSIVE_SIZES')){
109
+            if (config('media.CREATE_RESPONSIVE_SIZES')) {
110 110
 
111 111
                 Image::make($this->file_object)
112 112
                     ->widen(config('media.MEDIUM_IMAGE_SIZE'))
@@ -120,31 +120,31 @@  discard block
 block discarded – undo
120 120
                     ->widen(config('media.EXTRA_SMALL_IMAGE_SIZE'))
121 121
                     ->save(storage_path('app/'.$this->full_path_xs.'/'.$this->stored_name));
122 122
             }
123
-        }elseif($this->is($this->type)){
124
-            $this->file_object->storeAs(config('media.MAIN_UPLOAD_FOLDER').'/'.$this->type.'s',$stored_name);
123
+        }elseif ($this->is($this->type)) {
124
+            $this->file_object->storeAs(config('media.MAIN_UPLOAD_FOLDER').'/'.$this->type.'s', $stored_name);
125 125
         }
126 126
     }
127 127
 
128
-    public function remove(){
129
-        if($this->delete()){
130
-            if($this->is('image')){
128
+    public function remove() {
129
+        if ($this->delete()) {
130
+            if ($this->is('image')) {
131 131
                 Storage::delete($this->full_path_lg.'/'.$this->stored_name);
132 132
                 Storage::delete($this->full_path_md.'/'.$this->stored_name);
133 133
                 Storage::delete($this->full_path_sm.'/'.$this->stored_name);
134 134
                 Storage::delete($this->full_path_xs.'/'.$this->stored_name);
135
-            }else{
135
+            }else {
136 136
                 Storage::delete($this->full_path.'/'.$this->stored_name);
137 137
             }
138 138
             return true;
139
-        }else{
139
+        }else {
140 140
             return false;
141 141
         }
142 142
     }
143 143
 
144
-    public function url($image_size = 'lg'){
145
-        if($this->is('image')){
144
+    public function url($image_size = 'lg') {
145
+        if ($this->is('image')) {
146 146
             return Storage::url($this->main_upload_folder."/images/{$image_size}/".$this->stored_name);
147
-        }else{
147
+        }else {
148 148
             return Storage::url($this->main_upload_folder."/{$this->type}s/".$this->stored_name);
149 149
         }
150 150
     }
@@ -155,23 +155,23 @@  discard block
 block discarded – undo
155 155
         return $this->file_name.'.'.$this->extension;
156 156
     }
157 157
 
158
-    public function getMainUploadFolderAttribute(){
158
+    public function getMainUploadFolderAttribute() {
159 159
         return config('media.MAIN_UPLOAD_FOLDER');
160 160
     }
161 161
 
162
-    public function getFullPathLgAttribute(){
162
+    public function getFullPathLgAttribute() {
163 163
         return $this->main_upload_folder.'/images/'.config('media.LARGE_IMAGE_FOLDER_PATH');
164 164
     }
165 165
 
166
-    public function getFullPathMdAttribute(){
166
+    public function getFullPathMdAttribute() {
167 167
         return $this->main_upload_folder.'/images/'.config('media.MEDIUM_IMAGE_FOLDER_PATH');
168 168
     }
169 169
 
170
-    public function getFullPathSmAttribute(){
170
+    public function getFullPathSmAttribute() {
171 171
         return $this->main_upload_folder.'/images/'.config('media.SMALL_IMAGE_FOLDER_PATH');
172 172
     }
173 173
 
174
-    public function getFullPathXsAttribute(){
174
+    public function getFullPathXsAttribute() {
175 175
         return $this->main_upload_folder.'/images/'.config('media.EXTRA_SMALL_IMAGE_FOLDER_PATH');
176 176
     }
177 177
 
@@ -180,17 +180,17 @@  discard block
 block discarded – undo
180 180
         return $this->main_upload_folder."/{$this->type}s/";
181 181
     }
182 182
 
183
-    public function getTypeAttribute(){
184
-        return explode('/',$this->mime)[0];
183
+    public function getTypeAttribute() {
184
+        return explode('/', $this->mime)[0];
185 185
     }
186 186
 
187 187
     /********************** DETERMINERS *********************/
188 188
 
189
-    public function is($type){
190
-        return preg_match("/{$type}\/*/",$this->mime);
189
+    public function is($type) {
190
+        return preg_match("/{$type}\/*/", $this->mime);
191 191
     }
192 192
 
193
-    public function store_file_name_hashed(){
193
+    public function store_file_name_hashed() {
194 194
         return config('media.STORE_FILE_NAME_HASHED');
195 195
     }
196 196
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
     public function scopeByType($query, $type)
205 205
     {
206
-        return $query->where('mime', 'LIKE', $type.'/%' );
206
+        return $query->where('mime', 'LIKE', $type.'/%');
207 207
     }
208 208
 
209 209
     public function scopeImages($query)
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
         return $query->where('mime', 'LIKE', 'video/%');
217 217
     }
218 218
 
219
-    public function scopeOf($query, $value){
219
+    public function scopeOf($query, $value) {
220 220
         return $query->where('mediumable_type', $value);
221 221
     }
222 222
 
Please login to merge, or discard this patch.
Braces   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
             File::isDirectory($medium_image_folder) or File::makeDirectory($medium_image_folder, 0777, true, true);
40 40
             File::isDirectory($small_image_folder) or File::makeDirectory($small_image_folder, 0777, true, true);
41 41
             File::isDirectory($extra_small_image_folder) or File::makeDirectory($extra_small_image_folder, 0777, true, true);
42
-        }else{
42
+        } else{
43 43
             $path = storage_path('app/'.$this->main_upload_folder."/{$this->type}s/");
44 44
             File::isDirectory($path) or File::makeDirectory($path, 0777, true, true);
45 45
         }
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
             unset($this->width);
79 79
             unset($this->height);
80 80
             return true;
81
-        }else{
81
+        } else{
82 82
             return false;
83 83
         }
84 84
     }
@@ -102,7 +102,7 @@  discard block
 block discarded – undo
102 102
                 Image::make($this->file_object)
103 103
                     ->widen(config('media.LARGE_IMAGE_SIZE'))
104 104
                     ->save(storage_path('app/'.$this->full_path_lg.'/'.$stored_name));
105
-            }else{
105
+            } else{
106 106
                 $this->file_object->storeAs($this->full_path_lg, $stored_name);
107 107
             }
108 108
 
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
                     ->widen(config('media.EXTRA_SMALL_IMAGE_SIZE'))
121 121
                     ->save(storage_path('app/'.$this->full_path_xs.'/'.$this->stored_name));
122 122
             }
123
-        }elseif($this->is($this->type)){
123
+        } elseif($this->is($this->type)){
124 124
             $this->file_object->storeAs(config('media.MAIN_UPLOAD_FOLDER').'/'.$this->type.'s',$stored_name);
125 125
         }
126 126
     }
@@ -132,11 +132,11 @@  discard block
 block discarded – undo
132 132
                 Storage::delete($this->full_path_md.'/'.$this->stored_name);
133 133
                 Storage::delete($this->full_path_sm.'/'.$this->stored_name);
134 134
                 Storage::delete($this->full_path_xs.'/'.$this->stored_name);
135
-            }else{
135
+            } else{
136 136
                 Storage::delete($this->full_path.'/'.$this->stored_name);
137 137
             }
138 138
             return true;
139
-        }else{
139
+        } else{
140 140
             return false;
141 141
         }
142 142
     }
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
     public function url($image_size = 'lg'){
145 145
         if($this->is('image')){
146 146
             return Storage::url($this->main_upload_folder."/images/{$image_size}/".$this->stored_name);
147
-        }else{
147
+        } else{
148 148
             return Storage::url($this->main_upload_folder."/{$this->type}s/".$this->stored_name);
149 149
         }
150 150
     }
Please login to merge, or discard this patch.
src/routes/web.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,8 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 
3
-Route::group(['namespace'=>'Khaleghi\Media\Http\Controllers', 'middleware' => 'web'], function(){
3
+Route::group(['namespace'=>'Khaleghi\Media\Http\Controllers', 'middleware' => 'web'], function() {
4 4
 
5
-    Route::get('media/create','MediaController@create');
6
-    Route::post('media','MediaController@store')->name('media.store');
5
+    Route::get('media/create', 'MediaController@create');
6
+    Route::post('media', 'MediaController@store')->name('media.store');
7 7
 });
8 8
 
Please login to merge, or discard this patch.