Completed
Push — 1.x ( 229870...f5502a )
by Akihito
02:25
created

NamedPdoModule::bindNamedPdo()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 12
ccs 10
cts 10
cp 1
rs 9.4285
cc 1
eloc 9
nc 1
nop 4
crap 1
1
<?php
2
3
namespace Ray\AuraSqlModule;
4
5
use Aura\Sql\ExtendedPdo;
6
use Aura\Sql\ExtendedPdoInterface;
7
use Ray\Di\AbstractModule;
8
9
class NamedPdoModule extends AbstractModule
10
{
11
    /**
12
     * @var string
13
     */
14
    private $qualifer;
15
16
    /**
17
     * @var string
18
     */
19
    private $dsn;
20
21
    /**
22
     * @var string
23
     */
24
    private $user;
25
26
    /**
27
     * @var string
28
     */
29
    private $pass;
30
31
    /**
32
     * @param string $qualifer
33
     * @param string $dsn
34
     * @param string $user
35
     * @param string $pass
36
     */
37 2
    public function __construct($qualifer, $dsn, $user = '', $pass= '')
0 ignored issues
show
Coding Style introduced by
Incorrect spacing between argument "$pass" and equals sign; expected 1 but found 0
Loading history...
38
    {
39 2
        $this->qualifer = $qualifer;
40 2
        $this->dsn = $dsn;
41 2
        $this->user = $user;
42 2
        $this->pass = $pass;
43 2
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48 2
    protected function configure()
49
    {
50 2
        $this->bindNamedPdo($this->qualifer, $this->dsn, $this->user, $this->pass);
51 2
    }
52
53 2
    private function bindNamedPdo($qualifer, $dsn, $user, $pass)
54
    {
55 2
        $this->bind(ExtendedPdoInterface::class)
56 2
            ->annotatedWith($qualifer)
57 2
            ->toConstructor(
58 2
                ExtendedPdo::class,
59 2
                "dsn={$qualifer}_dsn,username={$qualifer}_username,password={$qualifer}_password"
60
            );
61 2
        $this->bind()->annotatedWith("{$qualifer}_dsn")->toInstance($dsn);
62 2
        $this->bind()->annotatedWith("{$qualifer}_username")->toInstance($user);
63 2
        $this->bind()->annotatedWith("{$qualifer}_password")->toInstance($pass);
64 2
    }
65
}
66