Completed
Push — master ( 9fc33c...1d1c21 )
by Innocent
01:18
created

UploadImage   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 7
dl 0
loc 39
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FaithGen\News\Jobs;
4
5
use FaithGen\News\Models\News;
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Contracts\Queue\ShouldQueue;
8
use Illuminate\Foundation\Bus\Dispatchable;
9
use Illuminate\Queue\InteractsWithQueue;
10
use Illuminate\Queue\SerializesModels;
11
use Intervention\Image\ImageManager;
12
13
class UploadImage implements ShouldQueue
14
{
15
    use Dispatchable,
16
        InteractsWithQueue,
17
        Queueable,
18
        SerializesModels;
19
20
    public bool $deleteWhenMissingModels = true;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
21
    protected News $article;
22
23
    protected $image;
24
25
    /**
26
     * Create a new job instance.
27
     *
28
     * @return void
29
     */
30
    public function __construct(News $article, $image)
31
    {
32
        $this->article = $article;
33
        $this->image = $image;
34
    }
35
36
    /**
37
     * Execute the job.
38
     *
39
     * @param ImageManager $imageManager
40
     *
41
     * @return void
42
     */
43
    public function handle(ImageManager $imageManager)
44
    {
45
        if ($this->image) {
46
            $fileName = str_shuffle($this->article->id.time().time()).'.png';
47
            $ogSave = storage_path('app/public/news/original/').$fileName;
48
            $imageManager->make($this->image)->save($ogSave);
49
            $this->article->image()->updateOrcreate([
50
                'imageable_id' => $this->article->id,
51
            ], [
52
                'name' => $fileName,
53
            ]);
54
        }
55
    }
56
}
57