LoaderRegistry   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
eloc 8
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A addLoader() 0 6 1
A getLoadableProperties() 0 5 1
A getLoader() 0 3 1
1
<?php
2
3
namespace Lneicelis\Transformer;
4
5
use Lneicelis\Transformer\Contract\CanLoad;
6
use Lneicelis\Transformer\Helper\Arr;
7
8
class LoaderRegistry
9
{
10
    /** @var array[] */
11
    private $loaderTree = [];
12
13 2
    public function addLoader(CanLoad $loader): void
14
    {
15 2
        $resourceClass = $loader->getResourceClass();
16 2
        $resourceProperty = $loader->getProperty();
17
18 2
        $this->loaderTree = Arr::setValue($this->loaderTree, [$resourceClass, $resourceProperty], $loader);
19 2
    }
20
21 2
    public function getLoader(string $resourceClass, string $resourceProperty): ?CanLoad
22
    {
23 2
        return $this->loaderTree[$resourceClass][$resourceProperty] ?? null;
24
    }
25
26 2
    public function getLoadableProperties(string $resourceClass): array
27
    {
28 2
        $loaderByProperty = $this->loaderTree[$resourceClass] ?? [];
29
30 2
        return array_keys($loaderByProperty);
31
    }
32
}
33