DownloadTextureController::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Http\Controllers\Api;
6
7
use Illuminate\Http\Response;
8
use Laravel\Lumen\Http\ResponseFactory;
9
use Laravel\Lumen\Routing\Controller as BaseController;
10
use Minepic\Helpers\Storage\Files\SkinsStorage;
11
use Minepic\Image\Sections\Raw;
12
use Minepic\Minecraft\MinecraftDefaults;
13
use Minepic\Resolvers\UuidResolver;
14
15
class DownloadTextureController extends BaseController
16
{
17
    public function __construct(
18
        protected UuidResolver $uuidResolver,
19
        protected ResponseFactory $responseFactory
20
    ) {
21
    }
22
23
    /**
24
     * Download user texture.
25
     *
26
     * @param string $uuid User UUID or Username
27
     *
28
     * @throws \Minepic\Image\Exceptions\ImageCreateFromPngFailedException
29
     */
30
    public function serve(string $uuid = ''): Response
31
    {
32
        $headers = [
33
            'Content-Disposition' => 'Attachment;filename='.$uuid.'.png',
34
            'Content-Type' => 'image/png',
35
        ];
36
37
        $skinPath = $this->uuidResolver->resolve($uuid) ?
38
            SkinsStorage::getPath($this->uuidResolver->getUuid()) :
0 ignored issues
show
Bug introduced by
It seems like $this->uuidResolver->getUuid() can also be of type null; however, parameter $uuid of Minepic\Helpers\Storage\Storage::getPath() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

38
            SkinsStorage::getPath(/** @scrutinizer ignore-type */ $this->uuidResolver->getUuid()) :
Loading history...
39
            SkinsStorage::getPath(MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME);
40
41
        $rawSkin = new Raw($skinPath);
42
        $rawSkin->render();
43
44
        return $this->responseFactory->make((string) $rawSkin, 200, $headers);
45
    }
46
}
47