Completed
Push — 1.x ( acb262...3883f9 )
by Akihito
11s
created

installReadWriteConnection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
ccs 1
cts 1
cp 1
crap 1
rs 10
c 1
b 0
f 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Ray\AuraSqlModule;
6
7
use Aura\Sql\ConnectionLocatorInterface;
8
use Aura\Sql\ExtendedPdoInterface;
9
use Override;
0 ignored issues
show
Bug introduced by
The type Override was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Ray\AuraSqlModule\Annotation\ReadOnlyConnection;
11
use Ray\AuraSqlModule\Annotation\WriteConnection;
12
use Ray\Di\AbstractModule;
13
use Ray\Di\Scope;
14
15
final class AuraSqlReplicationModule extends AbstractModule
16
{
17
    public function __construct(
18
        private readonly ConnectionLocatorInterface $connectionLocator,
19
        private readonly string $qualifer = '',
20
        ?AbstractModule $module = null
21
    ) {
22
        parent::__construct($module);
23
    }
24
25
    /**
26
     * {@inheritDoc}
27
     */
28 8
    #[Override]
29
    protected function configure(): void
30
    {
31
        if ($this->qualifer === '') {
32
            $this->configureWithoutQualifier();
33 8
        } else {
34 8
            $this->configureWithQualifier();
35 8
        }
36 8
37
        // @ReadOnlyConnection @WriteConnection
38
        $this->installReadWriteConnection();
39
    }
40
41 8
    private function configureWithoutQualifier(): void
42
    {
43 8
        $this->bind(ConnectionLocatorInterface::class)
44 8
            ->toInstance($this->connectionLocator);
45
46
        // ReadOnlyConnection when GET, otherwise WriteConnection
47 8
        $this->bind(ExtendedPdoInterface::class)
48
            ->toProvider(AuraSqlReplicationDbProvider::class, '')
49 8
            ->in(Scope::SINGLETON);
50
    }
51 8
52 8
    private function configureWithQualifier(): void
53
    {
54 8
        $this->bind(ConnectionLocatorInterface::class)
55
            /** @phpstan-ignore argument.type */
56
            ->annotatedWith($this->qualifer)
57 8
            ->toInstance($this->connectionLocator);
58 8
59 8
        // ReadOnlyConnection when GET, otherwise WriteConnection
60 8
        $this->bind(ExtendedPdoInterface::class)
61
            /** @phpstan-ignore argument.type */
62
            ->annotatedWith($this->qualifer)
63 8
            ->toProvider(AuraSqlReplicationDbProvider::class, $this->qualifer)
64 8
            ->in(Scope::SINGLETON);
65 8
    }
66 8
67
    protected function installReadWriteConnection(): void
68 8
    {
69
        // @ReadOnlyConnection
70
        $this->bindInterceptor(
71
            $this->matcher->any(),
72
            $this->matcher->annotatedWith(ReadOnlyConnection::class),
73
            [AuraSqlSlaveDbInterceptor::class],
0 ignored issues
show
Bug introduced by
The type Ray\AuraSqlModule\AuraSqlSlaveDbInterceptor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
74
        );
75
        // @WriteConnection
76
        $this->bindInterceptor(
77
            $this->matcher->any(),
78
            $this->matcher->annotatedWith(WriteConnection::class),
79
            [AuraSqlMasterDbInterceptor::class],
0 ignored issues
show
Bug introduced by
The type Ray\AuraSqlModule\AuraSqlMasterDbInterceptor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
80
        );
81
    }
82
}
83