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

TexturesPropertyValue   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 28
c 0
b 0
f 0
dl 0
loc 82
ccs 31
cts 31
cp 1
rs 10
wmc 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A getTimestamp() 0 2 1
A createFromRawTextures() 0 8 1
A isSignatureRequired() 0 2 1
A getCape() 0 6 2
A __construct() 0 12 1
A getProfileId() 0 2 1
A getProfileName() 0 2 1
A getSkin() 0 6 2
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