BeatMapVersion::getBsrKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace KriKrixs\object\beatmap;
4
5
use DateTime;
6
7
class BeatMapVersion
8
{
9
    private object $version;
10
11
    /**
12
     * Create a new BeatMapVersion object
13
     * @param object $version
14
     */
15
    public function __construct(object $version)
16
    {
17
        $this->version = $version;
18
    }
19
20
    /**
21
     * Return raw data
22
     * @return object
23
     */
24
    public function toJson(): object
25
    {
26
        return $this->version;
27
    }
28
29
    /**
30
     * Return array data
31
     * @return array
32
     */
33
    public function toArray(): array
34
    {
35
        return json_decode(json_encode($this->version), true);
36
    }
37
38
    /**
39
     * Get map version hash
40
     * @return string
41
     */
42
    public function getHash(): string
43
    {
44
        return $this->version->hash;
45
    }
46
47
    /**
48
     * Get map version BSR key (same as map ID)
49
     * @return string
50
     */
51
    public function getBsrKey(): string
52
    {
53
        return $this->version->key;
54
    }
55
56
    /**
57
     * Get map version ID (same as BSR Key)
58
     * @return string
59
     */
60
    public function getId(): string
61
    {
62
        return $this->version->key;
63
    }
64
65
    /**
66
     * Get map version state
67
     * @return string
68
     */
69
    public function getState(): string
70
    {
71
        return $this->version->state;
72
    }
73
74
    /**
75
     * Get map version creation date
76
     * @return DateTime|null
77
     */
78
    public function getCreationDate(): ?DateTime
79
    {
80
        try {
81
            return new DateTime($this->version->createdAt);
82
        } catch (\Exception $e) {
83
            return null;
84
        }
85
    }
86
87
    /**
88
     * Get map version sage score
89
     * @return int
90
     */
91
    public function getSageScore(): int
92
    {
93
        return $this->version->sageScore;
94
    }
95
96
    /**
97
     * Get map version difficulties (array of object)
98
     * @return array
99
     */
100
    public function getDifficulties(): array
101
    {
102
        $response = [];
103
104
        foreach ($this->version->diffs as $diff) {
105
            $response[] = new BeatMapVersionDifficulty($diff);
106
        }
107
108
        return $response;
109
    }
110
111
    /**
112
     * Get map version download url
113
     * @return string
114
     */
115
    public function getDownloadURL(): string
116
    {
117
        return $this->version->downloadURL;
118
    }
119
120
    /**
121
     * Get map version cover url
122
     * @return string
123
     */
124
    public function getCoverURL(): string
125
    {
126
        return $this->version->coverURL;
127
    }
128
129
    /**
130
     * Get map version preview url
131
     * @return string
132
     */
133
    public function getPreviewURL(): string
134
    {
135
        return $this->version->previewURL;
136
    }
137
}