Completed
Push — master ( eafdc3...b75110 )
by Jérémy
02:07
created

Helpers::candiesToMax()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 23
Code Lines 14

Duplication

Lines 23
Ratio 100 %

Importance

Changes 0
Metric Value
dl 23
loc 23
rs 9.0856
c 0
b 0
f 0
cc 2
eloc 14
nc 2
nop 2
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\Calculator;
10
11
use Th3Mouk\PokemonGoIVCalculator\Extractors\LevelExtractor;
12
13
class Helpers
14
{
15
    /**
16
     * Method to calculate how many dusts are necessary to max a pokemon
17
     * @param  float $pokemon the level of the pokemon
18
     * @param  float $trainer the level of the the trainer
19
     * @return int   dusts to max the pokemon
20
     */
21 View Code Duplication
    public static function dustsToMax(float $pokemon, float $trainer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $trainer += 1.5;
24
        $loop = $pokemon;
25
        $dusts = 0;
26
27
        $levels = (new LevelExtractor())
28
            ->getIntervalLevelFiltered($pokemon, $trainer);
29
30
        $levels
31
            ->each(function ($level) use (&$dusts, &$loop, $trainer) {
32
                $loop += 0.5;
33
                $dusts += $level->dust * 2;
34
            });
35
36
        if ($pokemon*2 % 2 === 1) {
37
            $dusts -= $levels->first()->dust;
38
        }
39
40
        $dusts -= $levels->last()->dust;
41
42
        return $dusts;
43
    }
44
45
    /**
46
     * Method to calculate how many candies are necessary to max a pokemon
47
     * @param  float $pokemon the level of the pokemon
48
     * @param  float $trainer the level of the the trainer
49
     * @return int   dusts to max the pokemon
50
     */
51 View Code Duplication
    public static function candiesToMax(float $pokemon, float $trainer)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
52
    {
53
        $trainer += 1.5;
54
        $loop = $pokemon;
55
        $candies = 0;
56
57
        $levels = (new LevelExtractor())
58
            ->getIntervalLevelFiltered($pokemon, $trainer);
59
60
        $levels
61
            ->each(function ($level) use (&$candies, &$loop, $trainer) {
62
                $loop += 0.5;
63
                $candies += $level->candy * 2;
64
            });
65
66
        if ($pokemon*2 % 2 === 1) {
67
            $candies -= $levels->first()->candy;
68
        }
69
70
        $candies -= $levels->last()->candy;
71
72
        return $candies;
73
    }
74
}
75