Passed
Push — master ( 60b6ca...163cac )
by Kylian
06:19
created

BeatMap::getName()   A

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 BeatMap
8
{
9
    private object $bm;
10
11
    /**
12
     * Create a new BeatMap object
13
     * @param object $beatmap
14
     */
15
    public function __construct(object $beatmap)
16
    {
17
        $this->bm = $beatmap;
18
    }
19
20
    /**
21
     * Return raw beatmap data
22
     * @return object
23
     */
24
    public function toJson(): object
25
    {
26
        return $this->bm;
27
    }
28
29
    /**
30
     * Get map ID (Same as BSR key)
31
     * @return string
32
     */
33
    public function getId(): string
34
    {
35
        return $this->bm->id;
36
    }
37
38
    /**
39
     * Get map BSR key (Same as ID)
40
     * @return string
41
     */
42
    public function getBsrKey(): string
43
    {
44
        return $this->bm->id;
45
    }
46
47
    /**
48
     * Get map name
49
     * @return string
50
     */
51
    public function getName(): string
52
    {
53
        return $this->bm->name;
54
    }
55
56
    /**
57
     * Get map description
58
     * @return string
59
     */
60
    public function getDescription(): string
61
    {
62
        return $this->bm->description;
63
    }
64
65
    /**
66
     * Get map upload date
67
     * @return DateTime|null
68
     */
69
    public function getUploadDate(): ?DateTime
70
    {
71
        try {
72
            return new DateTime($this->bm->uploaded);
73
        } catch (\Exception $e) {
74
            return null;
75
        }
76
    }
77
78
    /**
79
     * Get map creation date
80
     * @return DateTime|null
81
     */
82
    public function getCreateDate(): ?DateTime
83
    {
84
        try {
85
            return new DateTime($this->bm->createdAt);
86
        } catch (\Exception $e) {
87
            return null;
88
        }
89
    }
90
91
    /**
92
     * Get map update date
93
     * @return DateTime|null
94
     */
95
    public function getUpdateDate(): ?DateTime
96
    {
97
        try {
98
            return new DateTime($this->bm->updatedAt);
99
        } catch (\Exception $e) {
100
            return null;
101
        }
102
    }
103
104
    /**
105
     * Get map last publish date
106
     * @return DateTime|null
107
     */
108
    public function getLastPublishDate(): ?DateTime
109
    {
110
        try {
111
            return new DateTime($this->bm->lastPublishedAt);
112
        } catch (\Exception $e) {
113
            return null;
114
        }
115
    }
116
117
    /**
118
     * Is the map auto mapped ?
119
     * @return bool
120
     */
121
    public function isAutoMapped(): bool
122
    {
123
        return boolval($this->bm->automapper);
124
    }
125
126
    /**
127
     * Is the map ranked ?
128
     * @return bool
129
     */
130
    public function isRanked(): bool
131
    {
132
        return boolval($this->bm->ranked);
133
    }
134
135
    /**
136
     * Is the map qualified for ranking ?
137
     * @return bool
138
     */
139
    public function isQualified(): bool
140
    {
141
        return boolval($this->bm->qualified);
142
    }
143
144
    //////////////
145
    /// Object ///
146
    //////////////
147
148
    /**
149
     * Get map uploader (object)
150
     * @return BeatMapUploader
151
     */
152
    public function getUploader(): BeatMapUploader
153
    {
154
        return new BeatMapUploader($this->bm->uploader);
155
    }
156
157
    /**
158
     * Get map metadata (object)
159
     * @return BeatMapMetadata
160
     */
161
    public function getMetadata(): BeatMapMetadata
162
    {
163
        return new BeatMapMetadata($this->bm->metadata);
164
    }
165
166
    /**
167
     * Get map stats (object)
168
     * @return BeatMapStats
169
     */
170
    public function getStats(): BeatMapStats
171
    {
172
        return new BeatMapStats($this->bm->stats);
173
    }
174
175
    /**
176
     * Get map versions (array of object)
177
     * @return array
178
     */
179
    public function getVersions(): array
180
    {
181
        $response = [];
182
183
        foreach($this->bm->versions as $version) {
184
            $response[] = new BeatMapVersion($version);
185
        }
186
187
        return $response;
188
    }
189
}