Completed
Push — master ( a440a9...78d742 )
by Jérémy
03:36
created

LevelExtractor   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 2
dl 0
loc 48
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getGameMasterJson() 0 7 2
A getGameMasterJsonCollection() 0 7 2
A getDustFiltered() 0 5 1
A getExactLevel() 0 6 1
A getIntervalLevelFiltered() 0 7 3
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\Extractors;
10
11
use Illuminate\Support\Collection;
12
13
class LevelExtractor extends BaseExtractor
14
{
15
    private const FILE_PATH = __DIR__.'/../../datas/levels.json';
16
17
    protected $json = null;
18
19
    /**
20
     * @var Collection
21
     */
22
    protected $collection = null;
23
24
    public function getGameMasterJson()
25
    {
26
        if (null === $this->json) {
27
            $this->json = $this->loadJson(self::FILE_PATH);
28
        }
29
        return $this->json;
30
    }
31
32
    public function getGameMasterJsonCollection(): Collection
33
    {
34
        if (null === $this->collection) {
35
            $this->collection = new Collection($this->getGameMasterJson());
36
        }
37
        return $this->collection;
38
    }
39
40
    public function getDustFiltered(int $dusts)
41
    {
42
        return $this->getGameMasterJsonCollection()
43
            ->where('dust', $dusts);
44
    }
45
46
    public function getExactLevel(int $level)
47
    {
48
        return $this->getGameMasterJsonCollection()
49
            ->where('level', $level)
50
            ->first();
51
    }
52
53
    public function getIntervalLevelFiltered(float $min, float $max)
54
    {
55
        return $this->getGameMasterJsonCollection()
56
            ->filter(function ($level) use ($min, $max) {
57
                return (int)$min<=$level->level && $level->level<=(int)$max ? true: false;
58
            });
59
    }
60
}
61