BeatMap::getUpdateDate()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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