GetIcon::execute()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 2
nop 2
dl 0
loc 24
rs 9.7666
c 0
b 0
f 0
1
<?php
2
3
4
namespace App\Src\UseCases\Domain\Context\Queries;
5
6
7
use Intervention\Image\Facades\Image;
8
9
class GetIcon
10
{
11
    public function execute(string $uuid, ?int $dim)
12
    {
13
        $pathPicture = storage_path('app/public/characteristics/'.$uuid.'.png');
14
15
        $img = Image::make($pathPicture);
16
        $h = $img->height();
17
        $w = $img->width();
18
19
        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...
20
            return $img->response();
21
        }
22
23
        $img = Image::cache(function($image) use($pathPicture, $dim, $w, $h){
24
            if($w <= $h) {
25
                $image->make($pathPicture)->widen($dim, function ($constraint) {
26
                    $constraint->upsize();
27
                });
28
            }else{
29
                $image->make($pathPicture)->heighten($dim, function ($constraint) {
30
                    $constraint->upsize();
31
                });
32
            }
33
        }, 86400, true);
34
        return $img->response();
35
    }
36
37
}
38