Completed
Push — master ( 32f0b1...030226 )
by Ezra
14s queued 12s
created

Level::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 0
cts 8
cp 0
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Syntax\SteamApi\Containers\Player;
4
5
class Level
6
{
7
    public $playerXp;
8
9
    public $playerLevel;
10
11
    public $xpToLevelUp;
12
13
    public $xpForCurrentLevel;
14
15
    public $currentLevelFloor;
16
17
    public $currentLevelCeiling;
18
19
    public $percentThroughLevel;
20
21
    public function __construct($levelDetails)
22
    {
23
        $this->playerXp          = $levelDetails->player_xp;
24
        $this->playerLevel       = $levelDetails->player_level;
25
        $this->xpToLevelUp       = $levelDetails->player_xp_needed_to_level_up;
26
        $this->xpForCurrentLevel = $levelDetails->player_xp_needed_current_level;
27
28
        $this->currentLevelFloor   = $this->xpForCurrentLevel;
29
        $this->currentLevelCeiling = $this->playerXp + $this->xpToLevelUp;
30
31
        // arbitrary range formula. n = value in the middle ( n - min ) / ( max - min ) * 100
32
        $this->percentThroughLevel = ($this->playerXp - $this->currentLevelFloor) / ($this->currentLevelCeiling - $this->currentLevelFloor) * 100;
33
    }
34
}
35