PDOFactory::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
c 0
b 0
f 0
ccs 5
cts 5
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 3
crap 1
1
<?php
2
3
namespace TonicHealthCheck\Check\DB;
4
5
use PDO;
6
7
/**
8
 * Class PDOFactory.
9
 */
10
class PDOFactory implements PDOFactoryInterface
11
{
12
    /**
13
     * @var string
14
     */
15
    protected $dsn;
16
17
    /**
18
     * @var string
19
     */
20
    protected $user;
21
22
    /**
23
     * @var string
24
     */
25
    protected $password;
26
27
    /**
28
     * PDOFactoryInterface constructor.
29
     *
30
     * @param string $dsn
31
     * @param string $user
32
     * @param string $password
33
     */
34 7
    public function __construct($dsn, $user, $password)
35
    {
36 7
        $this->setDsn($dsn);
37 7
        $this->setUser($user);
38 7
        $this->setPassword($password);
39 7
    }
40
41
    /**
42
     * @return PDO
43
     */
44 4
    public function createPDO()
45
    {
46 4
        return new PDO($this->getDsn(), $this->getUser(), $this->getPassword());
47
    }
48
49
    /**
50
     * @return string
51
     */
52 4
    public function getDsn()
53
    {
54 4
        return $this->dsn;
55
    }
56
57
    /**
58
     * @return string
59
     */
60 4
    public function getUser()
61
    {
62 4
        return $this->user;
63
    }
64
65
    /**
66
     * @return string
67
     */
68 4
    public function getPassword()
69
    {
70 4
        return $this->password;
71
    }
72
73
    /**
74
     * @param string $dsn
75
     */
76 7
    protected function setDsn($dsn)
77
    {
78 7
        $this->dsn = $dsn;
79 7
    }
80
81
    /**
82
     * @param string $user
83
     */
84 7
    protected function setUser($user)
85
    {
86 7
        $this->user = $user;
87 7
    }
88
89
    /**
90
     * @param string $password
91
     */
92 7
    protected function setPassword($password)
93
    {
94 7
        $this->password = $password;
95 7
    }
96
}
97