AuraSqlReplicationModule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 54
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A configure() 0 12 2
A installReadWriteConnection() 0 15 1
1
<?php
2
/**
3
 * This file is part of the Ray.AuraSqlModule package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Ray\AuraSqlModule;
8
9
use Aura\Sql\ConnectionLocatorInterface;
10
use Aura\Sql\ExtendedPdoInterface;
11
use Ray\AuraSqlModule\Annotation\ReadOnlyConnection;
12
use Ray\AuraSqlModule\Annotation\WriteConnection;
13
use Ray\Di\AbstractModule;
14
use Ray\Di\Scope;
15
16
class AuraSqlReplicationModule extends AbstractModule
17
{
18
    /**
19
     * @var ConnectionLocatorInterface
20
     */
21
    private $connectionLocator;
22
23
    /**
24
     * @var string
25
     */
26
    private $qualifer;
27
28 8
    public function __construct(
29
        ConnectionLocatorInterface $connectionLocator,
30
        string $qualifer = '',
31
        AbstractModule $module = null
32
    ) {
33 8
        $this->connectionLocator = $connectionLocator;
34 8
        $this->qualifer = $qualifer;
35 8
        parent::__construct($module);
0 ignored issues
show
Bug introduced by
It seems like $module defined by parameter $module on line 31 can also be of type object<Ray\Di\AbstractModule>; however, Ray\Di\AbstractModule::__construct() does only seem to accept null|object<self>, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
36 8
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 8
    protected function configure()
42
    {
43 8
        if ($this->connectionLocator) {
44 8
            $this->bind(ConnectionLocatorInterface::class)->annotatedWith($this->qualifer)->toInstance($this->connectionLocator);
45
        }
46
        // ReadOnlyConnection when GET, otherwise WriteConnection
47 8
        $this->bind(ExtendedPdoInterface::class)->annotatedWith($this->qualifer)->toProvider(AuraSqlReplicationDbProvider::class, $this->qualifer)->in(Scope::SINGLETON);
48
        // @ReadOnlyConnection @WriteConnection
49 8
        $this->installReadWriteConnection();
50
        // @Transactional
51 8
        $this->install(new TransactionalModule);
0 ignored issues
show
Documentation introduced by
new \Ray\AuraSqlModule\TransactionalModule() is of type object<Ray\AuraSqlModule\TransactionalModule>, but the function expects a object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
52 8
    }
53
54 8
    protected function installReadWriteConnection()
55
    {
56
        // @ReadOnlyConnection
57 8
        $this->bindInterceptor(
58 8
            $this->matcher->any(),
59 8
            $this->matcher->annotatedWith(ReadOnlyConnection::class),
60 8
            [AuraSqlSlaveDbInterceptor::class]
61
        );
62
        // @WriteConnection
63 8
        $this->bindInterceptor(
64 8
            $this->matcher->any(),
65 8
            $this->matcher->annotatedWith(WriteConnection::class),
66 8
            [AuraSqlMasterDbInterceptor::class]
67
        );
68 8
    }
69
}
70