Completed
Push — master ( 5b54fc...16c96d )
by Bertrand
14:42
created

GetIcon::execute()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 15
nc 2
nop 2
dl 0
loc 24
rs 9.7666
c 1
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Agricultural\Queries;
5
6
7
use App\Src\UseCases\Domain\Ports\UserRepository;
8
use App\Src\UseCases\Domain\User;
9
use Intervention\Image\Facades\Image;
10
11
class GetIcon
12
{
13
    public function execute(string $uuid, ?int $dim)
14
    {
15
        $pathPicture = storage_path('app/public/characteristics/'.$uuid.'.png');
16
17
        $img = Image::make($pathPicture);
18
        $h = $img->height();
19
        $w = $img->width();
20
21
        if($dim == null){
0 ignored issues
show
Bug Best Practice introduced by
It seems like you are loosely comparing $dim of type integer|null against null; this is ambiguous if the integer can be zero. Consider using a strict comparison === instead.
Loading history...
22
            return $img->response();
23
        }
24
25
        $img = Image::cache(function($image) use($pathPicture, $dim, $w, $h){
26
            if($w <= $h) {
27
                $image->make($pathPicture)->widen($dim, function ($constraint) {
28
                    $constraint->upsize();
29
                });
30
            }else{
31
                $image->make($pathPicture)->heighten($dim, function ($constraint) {
32
                    $constraint->upsize();
33
                });
34
            }
35
        }, 3600, true);
36
        return $img->response();
37
    }
38
39
}
40