Rendering   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 21
dl 0
loc 75
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A imagePath() 0 3 2
A avatar() 0 8 1
A skinFront() 0 8 1
A isometricAvatar() 0 13 2
A skinBack() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Minepic\Image;
6
7
use Minepic\Helpers\Storage\Files\SkinsStorage;
8
use Minepic\Image\Components\Side;
9
use Minepic\Image\Sections\Avatar;
10
use Minepic\Image\Sections\SkinBack;
11
use Minepic\Image\Sections\SkinFront;
12
use Minepic\Minecraft\MinecraftDefaults;
13
14
class Rendering
15
{
16
    /**
17
     * @param string $type
18
     *
19
     * @throws Exceptions\ImageCreateFromPngFailedException
20
     * @throws Exceptions\ImageResourceCreationFailedException
21
     * @throws Exceptions\ImageTrueColorCreationFailedException
22
     * @throws \Exception
23
     */
24
    public function avatar(?string $uuid, int $size, $type = Side::FRONT): Avatar
25
    {
26
        $avatar = new Avatar(
27
            $this->imagePath($uuid)
28
        );
29
        $avatar->render($size, $type);
30
31
        return $avatar;
32
    }
33
34
    /**
35
     * @throws Exceptions\SkinNotFountException
36
     * @throws \Throwable
37
     */
38
    public function isometricAvatar(?string $uuid, int $size, int $lastUpdateTimestamp = null): IsometricAvatar
39
    {
40
        if ($lastUpdateTimestamp === null) {
41
            $lastUpdateTimestamp = time();
42
        }
43
44
        $isometricAvatar = new IsometricAvatar(
45
            $uuid ?? MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME,
46
            $lastUpdateTimestamp
47
        );
48
        $isometricAvatar->render($size);
49
50
        return $isometricAvatar;
51
    }
52
53
    /**
54
     * @throws Exceptions\ImageResourceCreationFailedException*@throws \Exception
55
     * @throws Exceptions\ImageCreateFromPngFailedException
56
     * @throws \Exception
57
     */
58
    public function skinFront(?string $uuid, int $size): SkinFront
59
    {
60
        $skin = new SkinFront(
61
            $this->imagePath($uuid)
62
        );
63
        $skin->render($size);
64
65
        return $skin;
66
    }
67
68
    /**
69
     * @throws Exceptions\ImageResourceCreationFailedException*@throws \Exception
70
     * @throws Exceptions\ImageCreateFromPngFailedException
71
     * @throws \Exception
72
     */
73
    public function skinBack(?string $uuid, int $size): SkinBack
74
    {
75
        $skin = new SkinBack(
76
            $this->imagePath($uuid)
77
        );
78
        $skin->render($size);
79
80
        return $skin;
81
    }
82
83
    /**
84
     * @throws \Exception
85
     */
86
    private function imagePath(?string $uuid): string
87
    {
88
        return $uuid !== null ? SkinsStorage::getPath($uuid) : SkinsStorage::getPath(MinecraftDefaults::STEVE_DEFAULT_SKIN_NAME);
89
    }
90
}
91