Conditions | 4 |
Paths | 4 |
Total Lines | 19 |
Code Lines | 15 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4.0313 |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
15 | 3 | public static function createAdapterFromConnection($connection) |
|
16 | { |
||
17 | 3 | if ($connection instanceof \PDO) { |
|
18 | 2 | switch ($connection->getAttribute(\PDO::ATTR_DRIVER_NAME)) { |
|
19 | 2 | case 'mysql': |
|
20 | 1 | $adapter = new Adapter\MysqlAdapter($connection); |
|
21 | 1 | break; |
|
22 | 1 | default: |
|
23 | 1 | $msg = "Currently only support 'pdo_mysql' connection"; |
|
24 | 1 | throw new Exception\InvalidArgumentException($msg); |
|
25 | 2 | } |
|
26 | 2 | } elseif ($connection instanceof \mysqli) { |
|
27 | 1 | $adapter = new Adapter\MysqlAdapter($connection); |
|
28 | 1 | } else { |
|
29 | $msg = "Currently only support 'pdo' or 'mysqli' connections"; |
||
30 | throw new Exception\InvalidArgumentException($msg); |
||
31 | } |
||
32 | 2 | return $adapter; |
|
33 | } |
||
34 | } |
||
35 |