Passed
Pull Request — 1.x (#346)
by Akihito
01:46
created

DataLoaderFactory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
dl 0
loc 15
rs 10
c 1
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create() 0 7 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\DataLoader;
6
7
use Override;
8
use Ray\Di\InjectorInterface;
9
10
use function assert;
11
12
/**
13
 * Factory for creating DataLoader instances using Ray.Di injector
14
 */
15
final class DataLoaderFactory implements DataLoaderFactoryInterface
16
{
17
    public function __construct(
18
        private readonly InjectorInterface $injector,
19
    ) {
20
    }
21
22
    /** @param class-string<DataLoaderInterface> $class */
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<DataLoaderInterface> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<DataLoaderInterface>.
Loading history...
23
    #[Override]
24
    public function create(string $class): DataLoaderInterface
25
    {
26
        $instance = $this->injector->getInstance($class);
27
        assert($instance instanceof DataLoaderInterface);
28
29
        return $instance;
30
    }
31
}
32