Completed
Pull Request — master (#6)
by Peter
03:25 queued 31s
created

DataMappingRepository::getStatMapping()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 10
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 2
1
<?php
2
3
namespace PtrTn\Battlerite\Repository;
4
5
use PtrTn\Battlerite\Repository\Dto\StatMapping;
6
7
class DataMappingRepository
8
{
9
    /**
10
     * @var array|null
11
     */
12
    private $mapping;
13
14 4
    public function getStatMapping($statKey): ?StatMapping
15
    {
16 4
        $this->lazyLoadData();
17
18 4
        if (!isset($this->mapping[$statKey])) {
19 2
            return null;
20
        }
21
22 3
        return StatMapping::createFromArray($this->mapping[$statKey]);
23
    }
24
25 4
    private function lazyLoadData(): void
26
    {
27 4
        if (!isset($this->mapping)) {
28 4
            $mappingJson = __DIR__ . '/../../../../data/statsMapping.json';
29 4
            $this->mapping = \GuzzleHttp\json_decode(file_get_contents($mappingJson), true);
30
        }
31 4
        return;
32
    }
33
}
34