Passed
Push — env_slave ( 209401 )
by Akihito
10:11
created

ConnectionLocatorProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 4
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ConnectionLocatorInterface;
8
use Ray\Di\Di\Named;
9
use Ray\Di\ProviderInterface;
10
use Ray\Di\SetContextInterface;
11
12
/**
13
 * @implements ProviderInterface<ConnectionLocatorInterface>
14
 */
15
final class ConnectionLocatorProvider implements ProviderInterface, SetContextInterface
16
{
17
    /** @var array<string> */
18
    private array $dsn;
19
20
    /** @var array<string> */
21
    private array $user;
22
23
    /** @var array<string> */
24
    private array $password;
25
26
    /** @var array<string> */
27
    private array $slave;
28
    private string $context;
29
30
    /**
31
     * {@inheritDoc}
32
     */
33
    public function setContext($context)
34
    {
35
        $this->context = $context;
36
    }
37
38
    /**
39
     * @param array<string> $dsn
40
     * @param array<string> $user
41
     * @param array<string> $password
42
     * @param array<string> $slave
43
     *
44
     * @Named("dsn=pdo_locator_dsn,user=pdo_locator_user,password=pdo_locator_pass,slave=pdo_locator_slave")
45
     */
46
    #[Named('dsn=pdo_locator_dsn,user=pdo_locator_user,password=pdo_locator_pass,slave=pdo_locator_slave')]
47
    public function __construct(array $dsn, array $user, array $password, array $slave)
48
    {
49
        $this->dsn = $dsn;
50
        $this->user = $user;
51
        $this->password = $password;
52
        $this->slave = $slave;
53
    }
54
55
    public function get(): ConnectionLocatorInterface
56
    {
57
        return ConnectionLocatorFactory::newInstance(
0 ignored issues
show
Bug Best Practice introduced by
The expression return Ray\AuraSqlModule...>slave[$this->context]) returns the type Aura\Sql\ConnectionLocator which is incompatible with the return type mandated by Ray\Di\ProviderInterface::get() of Ray\Di\T.

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
58
            $this->dsn[$this->context],
59
            $this->user[$this->context],
60
            $this->password[$this->context],
61
            $this->slave[$this->context]
62
        );
63
    }
64
}
65