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

DataLoaderFactory::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
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