Dbal2Connection::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Soluble\DbWrapper\Connection\Doctrine;
4
5
use Soluble\DbWrapper\Adapter\AdapterInterface;
6
use Soluble\DbWrapper\Exception;
7
use Soluble\DbWrapper\Connection\ConnectionInterface;
8
9
class Dbal2Connection implements ConnectionInterface
10
{
11
    /**
12
     * @var AdapterInterface;
13
     */
14
    protected $adapter;
15
16
    /**
17
     * @var \Doctrine\DBAL\Connection;
18
     */
19
    protected $dbal;
20
21
    /**
22
     * @param AdapterInterface          $adapter
23
     * @param \Doctrine\DBAL\Connection $dbal
24
     */
25 6
    public function __construct(AdapterInterface $adapter, \Doctrine\DBAL\Connection $dbal)
26
    {
27 6
        $this->adapter = $adapter;
28 6
        $this->dbal = $dbal;
29 6
    }
30
31
    /**
32
     * {@inheritdoc}
33
     *
34
     * @return mixed
35
     */
36 1
    public function getResource()
37
    {
38 1
        return $this->dbal->getWrappedConnection();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     *
44
     * @throws Exception\UnsupportedFeatureException
45
     */
46
    public function getHost()
47
    {
48
        throw new Exception\UnsupportedFeatureException(__METHOD__ . ' is not (yet) supported for doctrine dbal bridge');
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     *
54
     * @throws Exception\RuntimeException
55
     *
56
     * @return string
57
     */
58 1
    public function getCurrentSchema()
59
    {
60
        try {
61 1
            $schema = $this->dbal->getDatabase();
62
        } catch (\Exception $e) {
63
            throw new Exception\RuntimeException('Cannot retrieve current schema:' . $e->getMessage());
64
        }
65
66 1
        return $schema;
67
    }
68
}
69