Total Complexity | 6 |
Total Lines | 41 |
Duplicated Lines | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
11 | class GetAvatar |
||
12 | { |
||
13 | private $userRepository; |
||
14 | |||
15 | public function __construct(UserRepository $userRepository) |
||
16 | { |
||
17 | $this->userRepository = $userRepository; |
||
18 | } |
||
19 | |||
20 | public function execute(string $uuid, int $dim) |
||
21 | { |
||
22 | $user = $this->userRepository->getById($uuid); |
||
23 | $pathPicture = $this->getPathPicture($user); |
||
24 | |||
25 | $img = Image::make($pathPicture); |
||
26 | $h = $img->height(); |
||
27 | $w = $img->width(); |
||
28 | |||
29 | $img = Image::cache(function($image) use($pathPicture, $dim, $w, $h){ |
||
30 | if($w <= $h) { |
||
31 | $image->make($pathPicture)->widen($dim, function ($constraint) { |
||
32 | $constraint->upsize(); |
||
33 | }); |
||
34 | }else{ |
||
35 | $image->make($pathPicture)->heighten($dim, function ($constraint) { |
||
36 | $constraint->upsize(); |
||
37 | }); |
||
38 | } |
||
39 | }, 3600, true); |
||
40 | |||
41 | return $img->response(); |
||
42 | |||
43 | } |
||
44 | |||
45 | |||
46 | private function getPathPicture(?User $user): string |
||
52 | } |
||
53 | } |
||
54 |