Evaluation   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 79
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getIVs() 0 4 1
A getMaxPerfection() 0 4 1
A getAveragePerfection() 0 4 1
A getMinPerfection() 0 4 1
A __construct() 0 12 1
A calculatePerfection() 0 6 1
1
<?php
2
3
namespace IVCalculator\Entities;
4
5
use Illuminate\Support\Collection;
6
7
class Evaluation
8
{
9
    /**
10
     * @var Collection
11
     */
12
    private $ivs;
13
14
    /**
15
     * @var float
16
     */
17
    private $max;
18
19
    /**
20
     * @var float
21
     */
22
    public $min;
23
24
    /**
25
     * @var float
26
     */
27
    public $avg;
28
29
    public function __construct(Collection $ivs)
30
    {
31
        $this->ivs = $ivs->map(function (IV $iv) {
32
            $iv->perfection = $this->calculatePerfection($iv);
33
34
            return $iv;
35
        })->sortBy('perfection');
36
37
        $this->max = $this->ivs->first()->perfection;
38
        $this->min = $this->ivs->last()->perfection;
39
        $this->avg = round($this->ivs->average('perfection'), 2);
40
    }
41
42
    /**
43
     * @return Collection
44
     */
45
    public function getIVs()
46
    {
47
        return $this->ivs;
48
    }
49
50
    /**
51
     * @return float
52
     */
53
    public function getMaxPerfection()
54
    {
55
        return $this->max;
56
    }
57
58
    /**
59
     * @return float
60
     */
61
    public function getAveragePerfection()
62
    {
63
        return $this->avg;
64
    }
65
66
    /**
67
     * @return float
68
     */
69
    public function getMinPerfection()
70
    {
71
        return $this->min;
72
    }
73
74
    /**
75
     * @param IV $iv
76
     *
77
     * @return float
78
     */
79
    private function calculatePerfection(IV $iv)
80
    {
81
        $perfection = ($iv->attackIV + $iv->defenseIV + $iv->staminaIV) / 45;
82
83
        return floor($perfection * 100) / 100;
84
    }
85
}
86