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

SkinFrontController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 28
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A serve() 0 17 2
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 SkinFrontController extends BaseApiController
14
{
15
    /**
16
     * Serve 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
        $this->minepic->initialize($uuidOrName);
28
        $headers = $this->generateHttpCacheHeaders($this->minepic->getUserdata(), $size, 'avatar');
29
        $this->minepic->updateStats();
30
31
        if ($request->server('HTTP_IF_MODIFIED_SINCE')) {
32
            $avatarImage = '';
33
            $httpCode = 304;
34
        } else {
35
            $avatarImage = $this->minepic->renderSkinCurrentUser($size, 'F');
36
            $httpCode = 200;
37
            $headers['Content-Type'] = 'image/png';
38
        }
39
40
        return $this->responseFactory->make($avatarImage, $httpCode, $headers);
41
    }
42
}
43