Adodb::getADOConnectionId()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2
Metric Value
dl 0
loc 8
ccs 5
cts 5
cp 1
rs 9.4285
cc 2
eloc 5
nc 2
nop 1
crap 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