UploadImage   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 17
c 2
b 0
f 0
dl 0
loc 45
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 8 3
1
<?php
2
3
namespace FaithGen\SDK\Jobs\Users;
4
5
use FaithGen\SDK\Models\User;
6
use FaithGen\SDK\Traits\UploadsImages;
7
use Illuminate\Bus\Queueable;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Foundation\Bus\Dispatchable;
10
use Illuminate\Queue\InteractsWithQueue;
11
use Illuminate\Queue\SerializesModels;
12
use Intervention\Image\ImageManager;
13
14
class UploadImage implements ShouldQueue
15
{
16
    use Dispatchable,
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by FaithGen\SDK\Jobs\Users\UploadImage: $id, $relations, $class, $keyBy
Loading history...
Bug introduced by
The trait FaithGen\SDK\Traits\UploadsImages requires the property $id which is not provided by FaithGen\SDK\Jobs\Users\UploadImage.
Loading history...
17
        InteractsWithQueue,
18
        Queueable,
19
        SerializesModels,
20
        UploadsImages;
21
22
    public bool $deleteWhenMissingModels = true;
23
    /**
24
     * @var User
25
     */
26
    private User $user;
27
    /**
28
     * @var string
29
     */
30
    private string $image;
31
32
    /**
33
     * Create a new job instance.
34
     *
35
     * @param User $user
36
     * @param string $image
37
     */
38
    public function __construct(User $user, string $image)
39
    {
40
        $this->user = $user;
41
        $this->image = $image;
42
    }
43
44
    /**
45
     * Execute the job.
46
     *
47
     * @param ImageManager $imageManager
48
     *
49
     * @return void
50
     */
51
    public function handle(ImageManager $imageManager)
52
    {
53
        if ($this->image) {
54
            if ($this->user->image()->exists()) {
55
                $fileName = $this->user->image->name;
0 ignored issues
show
Bug introduced by
The property image does not seem to exist on FaithGen\SDK\Models\User. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
56
                $this->uploadImages($this->user, [$this->image], $imageManager, $fileName);
57
            } else {
58
                $this->uploadImages($this->user, [$this->image], $imageManager);
59
            }
60
        }
61
    }
62
}
63