Completed
Push — master ( 58c9ab...b3ba9b )
by Sébastien
19:11 queued 01:31
created

Capsule5Connection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 60
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getResource() 0 4 1
A getHost() 0 4 1
A getCurrentSchema() 0 9 2
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
    /**
13
     *
14
     * @var AdapterInterface;
15
     */
16
    protected $adapter;
17
18
    /**
19
     *
20
     * @var \Illuminate\Database\Capsule\Manager;
21
     */
22
    protected $capsule;
23
24
25
    /**
26
     * @param AdapterInterface $adapter
27
     * @param \Illuminate\Database\Capsule\Manager $capsule
28
     */
29
    public function __construct(AdapterInterface $adapter, \Illuminate\Database\Capsule\Manager $capsule)
30
    {
31
        $this->adapter = $adapter;
32
        $this->capsule = $capsule;
33
    }
34
35
36
    /**
37
     * {@inheritdoc}
38
     * @return \PDO
39
     */
40
    public function getResource()
41
    {
42
        return $this->capsule->getConnection()->getPdo();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     * @throws Exception\UnsupportedFeatureException
48
     */
49
    public function getHost()
50
    {
51
        throw new Exception\UnsupportedFeatureException(__METHOD__ . " is not (yet) supported for capsule bridge");
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     * @throws Exception\RuntimeException
57
     * @return string
58
     */
59
    public function getCurrentSchema()
60
    {
61
        try {
62
            $schema = $this->capsule->getConnection()->getDatabaseName();
63
        } catch (\Exception $e) {
64
            throw new Exception\RuntimeException("Cannot retrieve current schema:" . $e->getMessage());
65
        }
66
        return $schema;
67
    }
68
}
69