Passed
Push — master ( 10a915...0d23d6 )
by Mattia
08:28 queued 11s
created

IsometricAvatarController::serve()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 18
rs 9.8666
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 IsometricAvatarController extends BaseApiController
14
{
15
    /**
16
     * Serve isometric avatar.
17
     *
18
     * @param \Illuminate\Http\Request
19
     * @param string $uuidOrName
20
     * @param int    $size
21
     *
22
     * @throws \Throwable
23
     */
24
    public function serve(Request $request, $uuidOrName = '', $size = 0): Response
25
    {
26
        $size = (int) $size;
27
28
        $this->minepic->initialize($uuidOrName);
29
        $headers = $this->generateHttpCacheHeaders($this->minepic->getUserdata(), $size, 'avatar-isometric');
30
        $this->minepic->updateStats();
31
32
        if ($request->server('HTTP_IF_MODIFIED_SINCE')) {
33
            $avatarImage = '';
34
            $httpCode = 304;
35
        } else {
36
            $avatarImage = $this->minepic->isometricAvatarCurrentUser($size);
37
            $httpCode = 200;
38
            $headers['Content-Type'] = 'image/png';
39
        }
40
41
        return $this->responseFactory->make($avatarImage, $httpCode, $headers);
42
    }
43
}
44