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

ProcessImage::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 1
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 ProcessImage 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
    /**
24
     * Create a new job instance.
25
     *
26
     * @param News $article
27
     */
28
    public function __construct(News $article)
29
    {
30
        $this->article = $article;
31
    }
32
33
    /**
34
     * Execute the job.
35
     *
36
     * @param ImageManager $imageManager
37
     *
38
     * @return void
39
     */
40
    public function handle(ImageManager $imageManager)
41
    {
42
        if ($this->article->image()->exists()) {
43
            $ogImage = storage_path('app/public/news/original/').$this->article->image->name;
44
            $thumb100 = storage_path('app/public/news/100-100/').$this->article->image->name;
45
46
            $imageManager->make($ogImage)->fit(100, 100, function ($constraint) {
47
                $constraint->upsize();
48
                $constraint->aspectRatio();
49
            }, 'center')->save($thumb100);
50
        }
51
    }
52
}
53