LoaderRegistry::getLoader()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 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