Conditions | 5 |
Paths | 6 |
Total Lines | 28 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
12 | public static function makeFromApiResponse(array $response): MojangAccount |
||
13 | { |
||
14 | $uuid = $response['id']; |
||
15 | $username = $response['name']; |
||
16 | $skin = ''; |
||
17 | $cape = ''; |
||
18 | |||
19 | if (!\array_key_exists('properties', $response)) { |
||
20 | return new MojangAccount($uuid, $username, $skin, $cape); |
||
21 | } |
||
22 | |||
23 | $textures = array_filter($response['properties'], static function (array $entry) { |
||
24 | return $entry['name'] === 'textures'; |
||
25 | }); |
||
26 | |||
27 | if (!empty($textures)) { |
||
28 | $textureData = json_decode((string) base64_decode($textures[0]['value'], true), associative: true, flags: \JSON_THROW_ON_ERROR); |
||
29 | |||
30 | if (isset($textureData['textures']['SKIN']['url'])) { |
||
31 | $skin = self::extractTextureIdFromUrl($textureData['textures']['SKIN']['url']); |
||
32 | } |
||
33 | |||
34 | if (isset($textureData['textures']['CAPE']['url'])) { |
||
35 | $cape = self::extractTextureIdFromUrl($textureData['textures']['CAPE']['url']); |
||
36 | } |
||
37 | } |
||
38 | |||
39 | return new MojangAccount($uuid, $username, $skin, $cape); |
||
40 | } |
||
52 |