Passed
Push — master ( c06313...41d19b )
by Davide
89:23 queued 48:35
created

Organizer::user()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 0
cts 2
cp 0
rs 10
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
namespace DavideCasiraghi\LaravelEventsCalendar\Models;
4
5
use DavideCasiraghi\LaravelEventsCalendar\Facades\LaravelEventsCalendar;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Support\Str;
8
9
class Organizer extends Model
10
{
11
    /***************************************************************************/
12
    /**
13
     * The table associated with the model.
14
     *
15
     * @var string
16
     */
17
    protected $table = 'organizers';
18
19
    /***************************************************************************/
20
21
    protected $fillable = [
22
        'name', 'description', 'website', 'created_by', 'slug', 'email', 'phone',
23
    ];
24
25
    /***************************************************************************/
26
27
    /**
28
     * Get the user that owns the event. eg. $this->user.
29
     */
30
    public function user()
31
    {
32
        return $this->belongsTo('\Illuminate\Foundation\Auth\User', 'created_by');
33
    }
34
35
    /***************************************************************************/
36
37
    /**
38
     * Prepare the record to be saved on DB.
39
     * @param  array  $requestArray
40
     * @param  \Illuminate\Http\UploadedFile  $profilePicture
41
     * @return void
42
     */
43 3
    public function preSave(array $requestArray, $profilePicture): void
44
    {
45 3
        $this->name = $requestArray['name'];
46 3
        $this->description = clean($requestArray['description']);
47 3
        $this->website = $requestArray['website'];
48 3
        $this->email = $requestArray['email'];
49 3
        $this->phone = $requestArray['phone'];
50
51
        // Organizer profile picture upload
52 3
        if (!empty($profilePicture)) {
53
            $imageFile = $profilePicture;
54
            $imageName = $imageFile->hashName();
55
            $imageSubdir = 'organizers_profile';
56
            $imageWidth = 968;
57
            $thumbWidth = 300;
58
59
            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

59
            LaravelEventsCalendar::/** @scrutinizer ignore-call */ 
60
                                   uploadImageOnServer($imageFile, $imageName, $imageSubdir, $imageWidth, $thumbWidth);
Loading history...
60
            $this->profile_picture = $imageName;
61
        } else {
62 3
            if (array_key_exists("profile_picture",$requestArray)){
63
                $this->profile_picture = $requestArray['profile_picture'];
64
            }
65
        }
66
67
        //$this->created_by = Auth::id();
68 3
        $this->created_by = $requestArray['created_by'];
69 3
        if (! $this->slug) {
70 2
            $this->slug = Str::slug($this->name, '-').'-'.rand(10000, 100000);
71
        }
72 3
    }
73
}
74