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

BeatMapVersion::getDifficulties()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
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 9
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
     * Get map version hash
22
     * @return string
23
     */
24
    public function getHash(): string
25
    {
26
        return $this->version->hash;
27
    }
28
29
    /**
30
     * Get map version BSR key (same as map ID)
31
     * @return string
32
     */
33
    public function getBsrKey(): string
34
    {
35
        return $this->version->key;
36
    }
37
38
    /**
39
     * Get map version ID (same as BSR Key)
40
     * @return string
41
     */
42
    public function getId(): string
43
    {
44
        return $this->version->key;
45
    }
46
47
    /**
48
     * Get map version state
49
     * @return string
50
     */
51
    public function getState(): string
52
    {
53
        return $this->version->state;
54
    }
55
56
    /**
57
     * Get map version creation date
58
     * @return DateTime|null
59
     */
60
    public function getCreationDate(): ?DateTime
61
    {
62
        try {
63
            return new DateTime($this->version->createdAt);
64
        } catch (\Exception $e) {
65
            return null;
66
        }
67
    }
68
69
    /**
70
     * Get map version sage score
71
     * @return int
72
     */
73
    public function getSageScore(): int
74
    {
75
        return $this->version->sageScore;
76
    }
77
78
    /**
79
     * Get map version difficulties (array of object)
80
     * @return array
81
     */
82
    public function getDifficulties(): array
83
    {
84
        $response = [];
85
86
        foreach ($this->version->diffs as $diff) {
87
            $response[] = new BeatMapVersionDifficultyParitySummary($diff);
88
        }
89
90
        return $response;
91
    }
92
93
    /**
94
     * Get map version download url
95
     * @return string
96
     */
97
    public function getDownloadURL(): string
98
    {
99
        return $this->version->downloadURL;
100
    }
101
102
    /**
103
     * Get map version cover url
104
     * @return string
105
     */
106
    public function getCoverURL(): string
107
    {
108
        return $this->version->coverURL;
109
    }
110
111
    /**
112
     * Get map version preview url
113
     * @return string
114
     */
115
    public function getPreviewURL(): string
116
    {
117
        return $this->version->previewURL;
118
    }
119
}