Completed
Push — master ( 290642...116a3f )
by Sébastien
04:44
created

Capsule5Connection::getCurrentSchema()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.2559

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 3
cts 5
cp 0.6
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 6
nc 2
nop 0
crap 2.2559
1
<?php
2
3
namespace Soluble\DbWrapper\Connection\Laravel;
4
5
use Soluble\DbWrapper\Adapter\AdapterInterface;
6
use Soluble\DbWrapper\Exception;
7
use Soluble\DbWrapper\Connection\ConnectionInterface;
8
9
class Capsule5Connection implements ConnectionInterface
10
{
11
    /**
12
     * @var AdapterInterface;
13
     */
14
    protected $adapter;
15
16
    /**
17
     * @var \Illuminate\Database\Capsule\Manager;
18
     */
19
    protected $capsule;
20
21
    /**
22
     * @param AdapterInterface                     $adapter
23
     * @param \Illuminate\Database\Capsule\Manager $capsule
24
     */
25 6
    public function __construct(AdapterInterface $adapter, \Illuminate\Database\Capsule\Manager $capsule)
26
    {
27 6
        $this->adapter = $adapter;
28 6
        $this->capsule = $capsule;
29 6
    }
30
31
    /**
32
     * {@inheritdoc}
33
     *
34
     * @return \PDO
35
     */
36 1
    public function getResource()
37
    {
38 1
        return $this->capsule->getConnection()->getPdo();
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 capsule 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->capsule->getConnection()->getDatabaseName();
62
        } catch (\Exception $e) {
63
            throw new Exception\RuntimeException('Cannot retrieve current schema:' . $e->getMessage());
64
        }
65
66 1
        return $schema;
67
    }
68
}
69