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

DataMappingRepository   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 27
ccs 10
cts 10
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStatMapping() 0 10 2
A lazyLoadData() 0 8 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