Adodb   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 2 Features 0
Metric Value
wmc 6
c 2
b 2
f 0
lcom 0
cbo 5
dl 0
loc 46
ccs 20
cts 20
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getAdapter() 0 19 4
A getADOConnectionId() 0 8 2
1
<?php
2
/**
3
 *  Soluble Components (http://belgattitude.github.io/solublecomponents)
4
 *
5
 *  @link      http://github.com/belgattitude/solublecomponents for the canonical source repository
6
 *  @copyright Copyright (c) 2013-2014 Sébastien Vanvelthem
7
 *  @license   https://github.com/belgattitude/solublecomponents/blob/master/LICENSE.txt MIT License
8
 */
9
namespace Soluble\Db\Compat;
10
11
use Zend\Db\Adapter\Adapter;
12
13
class Adodb
14
{
15
    /**
16
     * Return a Zend\Db\Adapter\Adapter connection from an existing ADODb connection
17
     *
18
     * @throws Exception\UnsupportedDriverException
19
     * @throws Exception\AdoNotConnectedException when connection is not initialized
20
     *
21
     * @param \ADOConnection $adoConnection
22
     * @return Adapter
23
     */
24 5
    public static function getAdapter(\ADOConnection $adoConnection)
25
    {
26 5
        $adoConnectionDriver = strtolower(get_class($adoConnection));
27
        switch ($adoConnectionDriver) {
28
            //case 'adodb_mysqlt':
29 5
            case 'adodb_mysqli':
30 1
                $connectionId = self::getADOConnectionId($adoConnection);
31 1
                $adapter = Mysqli::getAdapter($connectionId);
32 1
                break;
33 4
            case 'adodb_pdo':
34 4
            case 'adodb_pdo_mysql':
35 3
                $connectionId = self::getADOConnectionId($adoConnection);
36 1
                $adapter = PDO::getAdapter($connectionId);
37 1
                break;
38 1
            default:
39 1
                throw new Exception\UnsupportedDriverException(__METHOD__ . ". Driver '$adoConnectionDriver' not supported");
40 1
        }
41 2
        return $adapter;
42
    }
43
44
    /**
45
     * Return internal adodb internal connection id
46
     * @throws Exception\AdoNotConnectedException when connection is not initialized
47
     * @param \ADOConnection $adoConnection
48
     * @return \MySQLI|\PDO
49
     */
50 4
    protected static function getADOConnectionId(\ADOConnection $adoConnection)
51
    {
52 4
        $connectionId = $adoConnection->_connectionID;
53 4
        if (!$connectionId) {
54 2
            throw new Exception\AdoNotConnectedException(__METHOD__ . ". Error: Invalid usage, adodb connection must be connected before use (see connect(), pconnect()");
55
        }
56 2
        return $connectionId;
57
    }
58
}
59