Completed
Push — master ( 99fa2d...6291ae )
by Ezra
02:24
created

Level::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 13
ccs 9
cts 9
cp 1
rs 9.8333
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
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 1
    public function __construct($levelDetails)
22
    {
23 1
        $this->playerXp          = $levelDetails->player_xp;
24 1
        $this->playerLevel       = $levelDetails->player_level;
25 1
        $this->xpToLevelUp       = $levelDetails->player_xp_needed_to_level_up;
26 1
        $this->xpForCurrentLevel = $levelDetails->player_xp_needed_current_level;
27
28 1
        $this->currentLevelFloor   = $this->xpForCurrentLevel;
29 1
        $this->currentLevelCeiling = $this->playerXp + $this->xpToLevelUp;
30
31
        // arbitrary range formula. n = value in the middle ( n - min ) / ( max - min ) * 100
32 1
        $this->percentThroughLevel = ($this->playerXp - $this->currentLevelFloor) / ($this->currentLevelCeiling - $this->currentLevelFloor) * 100;
33 1
    }
34
}
35