Organizer::user()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
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 1
    public function user()
31
    {
32 1
        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 4
    public function preSave(array $requestArray, $profilePicture): void
44
    {
45 4
        $this->name = $requestArray['name'];
46 4
        $this->description = clean($requestArray['description']);
47 4
        $this->website = $requestArray['website'] ?? null;
48 4
        $this->email = $requestArray['email'] ?? null;
49 4
        $this->phone = $requestArray['phone'] ?? null;
50
51
        // Organizer profile picture upload
52 4
        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 4
            if (array_key_exists('profile_picture', $requestArray)) {
63
                $this->profile_picture = $requestArray['profile_picture'];
64
            }
65
        }
66
67
        //$this->created_by = Auth::id();
68 4
        $this->created_by = $requestArray['created_by'] ?? null;
69 4
        if (! $this->slug) {
70 3
            $this->slug = Str::slug($this->name, '-').'-'.rand(10000, 100000);
71
        }
72 4
    }
73
}
74