Passed
Push — master ( 693377...95d81f )
by Davide
75:43
created

Organizer::preSave()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3.5293

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 18
c 1
b 0
f 0
dl 0
loc 25
ccs 11
cts 18
cp 0.6111
rs 9.6666
cc 3
nc 4
nop 1
crap 3.5293
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar;
7
use Illuminate\Http\Request;  // to remove
8
use Illuminate\Support\Str;
9
10
class Organizer extends Model
11
{
12
    /***************************************************************************/
13
    /**
14
     * The table associated with the model.
15
     *
16
     * @var string
17
     */
18
    protected $table = 'organizers';
19
20
    /***************************************************************************/
21
22
    protected $fillable = [
23
        'name', 'description', 'website', 'created_by', 'slug', 'email', 'phone',
24
    ];
25
26
    /***************************************************************************/
27
28
    /**
29
     * Get the user that owns the event. eg. $this->user.
30
     */
31
    public function user()
32
    {
33
        return $this->belongsTo('\Illuminate\Foundation\Auth\User', 'created_by');
34
    }
35
    
36
    /**
37
     * Prepare datas for save model on DB
38
     * @param  \Illuminate\Http\Request  $request
39
     * @return void
40
     */
41 3
    public function preSave(Request $request){
42 3
        $this->name = $request->get('name');
43 3
        $this->description = clean($request->get('description'));
44 3
        $this->website = $request->get('website');
45 3
        $this->email = $request->get('email');
46 3
        $this->phone = $request->get('phone');
47
48
        // Organizer profile picture upload
49 3
        if ($request->file('profile_picture')) {
50
            $imageFile = $request->file('profile_picture');
51
            $imageName = $imageFile->hashName();
52
            $imageSubdir = 'organizers_profile';
53
            $imageWidth = 968;
54
            $thumbWidth = 300;
55
56
            LaravelEventsCalendar::uploadImageOnServer($imageFile, $imageName, $imageSubdir, $imageWidth, $thumbWidth);
0 ignored issues
show
Bug introduced by
The method uploadImageOnServer() does not exist on DavideCasiraghi\LaravelE...s\LaravelEventsCalendar. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

56
            LaravelEventsCalendar::/** @scrutinizer ignore-call */ 
57
                                   uploadImageOnServer($imageFile, $imageName, $imageSubdir, $imageWidth, $thumbWidth);
Loading history...
57
            $this->profile_picture = $imageName;
58
        } else {
59 3
            $this->profile_picture = $request->profile_picture;
60
        }
61
62
        //$this->created_by = Auth::id();
63 3
        $this->created_by = $request->get('created_by');
64 3
        if (! $this->slug) {
65 2
            $this->slug = Str::slug($this->name, '-').'-'.rand(10000, 100000);
66
        }
67 3
    }
68
}
69