Passed
Push — master ( 288b46...98b0e3 )
by Nico
31:30 queued 08:00
created

CommodityCache   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 33.33%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 7
c 1
b 0
f 1
dl 0
loc 22
ccs 2
cts 6
cp 0.3333
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 7 2
A __construct() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Stu\Module\Commodity\Lib;
6
7
use Stu\Orm\Entity\CommodityInterface;
8
use Stu\Orm\Repository\CommodityRepositoryInterface;
9
10
final class CommodityCache implements CommodityCacheInterface
11
{
12
    private CommodityRepositoryInterface $commodityRepository;
13
14
    /**
15
     * @var array<int, CommodityInterface>|null
16
     */
17
    private ?array $commodityArray = null;
18
19 2
    public function __construct(
20
        CommodityRepositoryInterface $commodityRepository
21
    ) {
22 2
        $this->commodityRepository = $commodityRepository;
23
    }
24
25
    public function get(int $commodityId): CommodityInterface
26
    {
27
        if ($this->commodityArray === null) {
28
            $this->commodityArray = $this->commodityRepository->getAll();
29
        }
30
31
        return $this->commodityArray[$commodityId];
32
    }
33
}
34