Completed
Push — 1.x ( 980d56...edf1de )
by Akihito
14s queued 12s
created

NamedExtendedPdoProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ExtendedPdo;
8
use Ray\Di\InjectorInterface;
9
use Ray\Di\ProviderInterface;
10
use Ray\Di\SetContextInterface;
11
12
use function assert;
13
14
/**
15
 * @implements ProviderInterface<ExtendedPdo>
16
 */
17
18
class NamedExtendedPdoProvider implements ProviderInterface, SetContextInterface
19
{
20
    private InjectorInterface $injector;
21
    private string $context;
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    public function setContext($context)
27
    {
28
        $this->context = $context;
29
    }
30
31
    public function __construct(InjectorInterface $injector)
32
    {
33
        $this->injector = $injector;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function get(): ExtendedPdo
40
    {
41
        $connection = $this->injector->getInstance(EnvConnection::class, $this->context);
42
        assert($connection instanceof EnvConnection);
43
44
        return ($connection)();
45
    }
46
}
47