AvatarController::serveDefault()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Http\Controllers\Api;
6
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Response;
9
10
class AvatarController extends BaseApiController
11
{
12
    /**
13
     * Serve Avatar.
14
     *
15
     * @param int    $size
16
     *
17
     * @throws \Throwable
18
     */
19
    public function serveUuid(Request $request, string $uuid, $size = 0): Response
20
    {
21
        $this->uuidResolver->resolve($uuid);
22
        $this->dispatchAccountImageServedEvent();
23
24
        return $this->pngResponse(
25
            (string) $this->rendering->avatar(
26
                $this->uuidResolver->getUuid(),
27
                (int) $size
28
            )
29
        );
30
    }
31
32
    /**
33
     * @param int|string $size
34
     */
35
    public function serveDefault($size = 0): Response
36
    {
37
        $image = $this->cache()->remember('rendering.system.default_avatar', 3600, function () use ($size) {
38
            return (string) $this->rendering->avatar(
39
                null,
40
                (int) $size
41
            );
42
        });
43
44
        return $this->pngResponse($image);
45
    }
46
}
47