Passed
Push — master ( 3f12a7...90c355 )
by Mattia
05:24
created

AvatarController::serve()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 9
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace App\Http\Controllers\Api;
6
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Response;
9
10
/**
11
 * Class BaseApiController.
12
 */
13
class AvatarController extends BaseApiController
14
{
15
    /**
16
     * Serve Avatar.
17
     *
18
     * @param \Illuminate\Http\Request
19
     * @param string $uuid
20
     * @param int    $size
21
     *
22
     * @throws \Throwable
23
     *
24
     * @return \Illuminate\Http\Response
25
     */
26
    public function serveUuid(Request $request, string $uuid, $size = 0): Response
27
    {
28
        $size = (int) $size;
29
30
        $this->minepic->initialize($uuid);
31
        $this->minepic->updateStats();
32
33
        return $this->pngResponse(
34
            (string) $this->minepic->avatarCurrentUser($size)
35
        );
36
    }
37
38
    /**
39
     * @param Request $request
40
     * @param string  $username
41
     * @param int     $size
42
     *
43
     * @throws \Throwable
44
     *
45
     * @return Response
46
     */
47
    public function serveUsername(Request $request, string $username, $size = 0): Response
48
    {
49
        $size = (int) $size;
50
51
        $this->minepic->initialize($username);
52
        $this->minepic->updateStats();
53
54
        return $this->pngResponse(
55
            (string) $this->minepic->avatarCurrentUser($size)
56
        );
57
    }
58
}
59