PdoMysqlAdapter::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace Soluble\DbWrapper\Adapter;
4
5
use Soluble\DbWrapper\Exception;
6
use Soluble\DbWrapper\Adapter\Pdo\GenericPdo;
7
use Soluble\DbWrapper\Connection\PdoMysqlConnection;
8
use PDO;
9
10
class PdoMysqlAdapter extends GenericPdo implements AdapterInterface
11
{
12
    /**
13
     * @var \PDO
14
     */
15
    protected $resource;
16
17
    /**
18
     * @var PdoMysqlConnection
19
     */
20
    protected $connection;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @throws Exception\InvalidArgumentException
26
     * @throws Exception\RuntimeException
27
     *
28
     * @param \PDO $resource
29
     */
30 13
    public function __construct(PDO $resource)
31
    {
32 13
        $this->checkEnvironment();
33 13
        if ($resource->getAttribute(\PDO::ATTR_DRIVER_NAME) != 'mysql') {
34 1
            $msg = __CLASS__ . " requires pdo connection to be 'mysql'";
35 1
            throw new Exception\InvalidArgumentException($msg);
36
        }
37 13
        $this->resource = $resource;
38 13
        $this->connection = new PdoMysqlConnection($this, $resource);
39 13
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @return MysqlConnection
45
     */
46 4
    public function getConnection()
47
    {
48 4
        return $this->connection;
49
    }
50
}
51