LevelExtractor::getGameMasterJson()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 0
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