ProcessImage::handle()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 2
b 0
f 0
nc 2
nop 1
dl 0
loc 10
rs 10
1
<?php
2
3
namespace Innoflash\Events\Listeners\Guest\Saved;
4
5
use Illuminate\Contracts\Queue\ShouldQueue;
6
use Innoflash\Events\Events\Guest\Saved;
7
use Intervention\Image\ImageManager;
8
9
class ProcessImage implements ShouldQueue
10
{
11
    protected $imageManager;
12
13
    /**
14
     * Create the event listener.
15
     *
16
     * @return void
17
     */
18
    public function __construct(ImageManager $imageManager)
19
    {
20
        $this->imageManager = $imageManager;
21
    }
22
23
    /**
24
     * Handle the event.
25
     *
26
     * @param  Saved  $event
27
     *
28
     * @return void
29
     */
30
    public function handle(Saved $event)
31
    {
32
        if ($event->getGuest()->image()->exists()) {
33
            $ogImage = storage_path('app/public/events/original/').$event->getGuest()->image->name;
0 ignored issues
show
Bug introduced by
The property image does not seem to exist on Innoflash\Events\Models\Guest. 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...
34
            $thumb100 = storage_path('app/public/events/50-50/').$event->getGuest()->image->name;
35
36
            $this->imageManager->make($ogImage)->fit(50, 50, function ($constraint) {
37
                $constraint->upsize();
38
                $constraint->aspectRatio();
39
            }, 'center')->save($thumb100);
40
        }
41
    }
42
}
43