NamedExtendedPdoProvider::get()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
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
/** @implements ProviderInterface<ExtendedPdo> */
15
16
class NamedExtendedPdoProvider implements ProviderInterface, SetContextInterface
17
{
18
    private InjectorInterface $injector;
19
    private string $context;
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function setContext($context)
25
    {
26
        $this->context = $context;
27
    }
28
29
    public function __construct(InjectorInterface $injector)
30
    {
31
        $this->injector = $injector;
32
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37
    public function get(): ExtendedPdo
38
    {
39
        $connection = $this->injector->getInstance(EnvConnection::class, $this->context);
40
        assert($connection instanceof EnvConnection);
41
42
        return ($connection)();
43
    }
44
}
45