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

UserStats::getAverageBPM()   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\user;
4
5
use DateTime;
6
7
class UserStats
8
{
9
    private object $stats;
10
11
    /**
12
     * Create a new UserStats object
13
     * @param object $stats
14
     */
15
    public function __construct(object $stats)
16
    {
17
        $this->stats = $stats;
18
    }
19
20
    /**
21
     * Get user stats total upvotes
22
     * @return int
23
     */
24
    public function getTotalUpvotes(): int
25
    {
26
        return $this->stats->totalUpvotes;
27
    }
28
29
    /**
30
     * Get user stats total downvotes
31
     * @return int
32
     */
33
    public function getTotalDownvotes(): int
34
    {
35
        return $this->stats->totalDownvotes;
36
    }
37
38
    /**
39
     * Get user stats total maps
40
     * @return int
41
     */
42
    public function getTotalMaps(): int
43
    {
44
        return $this->stats->totalMaps;
45
    }
46
47
    /**
48
     * Get user stats total ranked maps
49
     * @return int
50
     */
51
    public function getTotalRankedMaps(): int
52
    {
53
        return $this->stats->rankedMaps;
54
    }
55
56
    /**
57
     * Get user stats average bpm
58
     * @return float
59
     */
60
    public function getAverageBPM(): float
61
    {
62
        return $this->stats->avgBpm;
63
    }
64
65
    /**
66
     * Get user stats average score
67
     * @return float
68
     */
69
    public function getAverageScore(): float
70
    {
71
        return $this->stats->avgScore;
72
    }
73
74
    /**
75
     * Get user stats average duration
76
     * @return int
77
     */
78
    public function getAverageDuration(): int
79
    {
80
        return $this->stats->avgDuration;
81
    }
82
83
    /**
84
     * Get user stats first upload date
85
     * @return DateTime|null
86
     */
87
    public function getFirstUploadDate(): ?DateTime
88
    {
89
        try {
90
            return new DateTime($this->stats->firstUpload);
91
        } catch (\Exception $e) {
92
            return null;
93
        }
94
    }
95
96
    /**
97
     * Get user stats last upload date
98
     * @return DateTime|null
99
     */
100
    public function getLastUploadDate(): ?DateTime
101
    {
102
        try {
103
            return new DateTime($this->stats->lastUpload);
104
        } catch (\Exception $e) {
105
            return null;
106
        }
107
    }
108
109
    /**
110
     * Get UserStatsDifficulties object
111
     * @return UserStatsDifficulties
112
     */
113
    public function getDifficulties(): UserStatsDifficulties
114
    {
115
        return new UserStatsDifficulties($this->stats->diffStats);
116
    }
117
}