Level   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 95
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 95
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A getLevel() 0 7 2
A getDust() 0 4 1
B getCpScalar() 0 14 5
A isUpgraded() 0 4 1
1
<?php
2
3
/*
4
 * (c) Jérémy Marodon <[email protected]>
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
9
namespace Th3Mouk\PokemonGoIVCalculator\Entities;
10
11
class Level
12
{
13
    private const ADSCALAR_UNDER_10 = 0.009426125571;
14
    private const ADSCALAR_UNDER_20 = 0.008919021209;
15
    private const ADSCALAR_UNDER_30 = 0.008924887876;
16
    private const ADSCALAR_UNDER_40 = 0.00445945781;
17
18
    /**
19
     * @var int
20
     */
21
    protected $level;
22
23
    /**
24
     * @var int
25
     */
26
    protected $dust;
27
28
    /**
29
     * @var float
30
     */
31
    protected $cpScalar;
32
33
    /**
34
     * @var bool
35
     */
36
    protected $upgraded;
37
38
    /**
39
     * Level constructor.
40
     * @param int   $level
41
     * @param int   $dust
42
     * @param float $cpScalar
43
     * @param bool  $upgraded
44
     */
45
    public function __construct($level, $dust, $cpScalar, $upgraded = false)
46
    {
47
        $this->level = $level;
48
        $this->dust = $dust;
49
        $this->cpScalar = $cpScalar;
50
        $this->upgraded = $upgraded;
51
    }
52
53
    /**
54
     * Get level
55
     *
56
     * @return float
57
     */
58
    public function getLevel(): float
59
    {
60
        if ($this->upgraded) {
61
            return $this->level + 0.5;
62
        }
63
        return $this->level;
64
    }
65
66
    /**
67
     * Get dust
68
     *
69
     * @return int
70
     */
71
    public function getDust(): int
72
    {
73
        return $this->dust;
74
    }
75
76
    /**
77
     * Get CP Scalar by Pokemon level
78
     *
79
     * @return float
80
     */
81
    public function getCpScalar(): float
82
    {
83
        if ($this->isUpgraded()) {
84
            if ($this->level < 10) {
85
                return sqrt(pow($this->cpScalar, 2) + self::ADSCALAR_UNDER_10);
86
            } elseif ($this->level < 20) {
87
                return sqrt(pow($this->cpScalar, 2) + self::ADSCALAR_UNDER_20);
88
            } elseif ($this->level < 30) {
89
                return sqrt(pow($this->cpScalar, 2) + self::ADSCALAR_UNDER_30);
90
            }
91
            return sqrt(pow($this->cpScalar, 2) + self::ADSCALAR_UNDER_40);
92
        }
93
        return $this->cpScalar;
94
    }
95
96
    /**
97
     * Get upgraded
98
     *
99
     * @return bool
100
     */
101
    public function isUpgraded(): bool
102
    {
103
        return $this->upgraded;
104
    }
105
}
106