Passed
Push — master ( bbc85b...f0bc06 )
by
04:59
created

TexturesPropertyValue::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 5
c 0
b 0
f 0
nc 1
nop 5
dl 0
loc 12
ccs 6
cts 6
cp 1
crap 1
rs 10
1
<?php
2
declare(strict_types=1);
3
4
namespace Ely\Mojang\Response\Properties;
5
6
class TexturesPropertyValue {
7
8
    /**
9
     * @var string
10
     */
11
    private $id;
12
13
    /**
14
     * @var string
15
     */
16
    private $username;
17
18
    /**
19
     * @var array
20
     */
21
    private $textures;
22
23
    /**
24
     * @var int
25
     */
26
    private $timestamp;
27
28
    /**
29
     * @var bool
30
     */
31
    private $signatureRequired;
32
33 4
    public function __construct(
34
        string $profileId,
35
        string $profileName,
36
        array $textures,
37
        int $timestamp,
38
        bool $signatureRequired = false
39
    ) {
40 4
        $this->id = $profileId;
41 4
        $this->username = $profileName;
42 4
        $this->textures = $textures;
43 4
        $this->timestamp = (int)floor($timestamp / 1000);
44 4
        $this->signatureRequired = $signatureRequired;
45 4
    }
46
47 2
    public static function createFromRawTextures(string $rawTextures): self {
48 2
        $decoded = json_decode(base64_decode($rawTextures), true);
49 2
        return new static(
50 2
            $decoded['profileId'],
51 2
            $decoded['profileName'],
52 2
            $decoded['textures'],
53 2
            $decoded['timestamp'],
54 2
            $decoded['signatureRequired'] ?? false
55
        );
56
    }
57
58 2
    public function getProfileId(): string {
59 2
        return $this->id;
60
    }
61
62 2
    public function getProfileName(): string {
63 2
        return $this->username;
64
    }
65
66 2
    public function getTimestamp(): int {
67 2
        return $this->timestamp;
68
    }
69
70 2
    public function isSignatureRequired(): bool {
71 2
        return $this->signatureRequired;
72
    }
73
74 3
    public function getSkin(): ?TexturesPropertyValueSkin {
75 3
        if (!isset($this->textures['SKIN'])) {
76 1
            return null;
77
        }
78
79 3
        return TexturesPropertyValueSkin::createFromTextures($this->textures['SKIN']);
80
    }
81
82 3
    public function getCape(): ?TexturesPropertyValueCape {
83 3
        if (!isset($this->textures['CAPE'])) {
84 2
            return null;
85
        }
86
87 2
        return new TexturesPropertyValueCape($this->textures['CAPE']['url']);
88
    }
89
90
}
91