Completed
Push — master ( fd5a8f...ebf9fc )
by Oleg
04:44
created

Connection   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A setDriver() 0 8 1
A __call() 0 8 2
1
<?php /** ConnectionMicro */
2
3
namespace Micro\Db;
4
5
/**
6
 * Threads class file.
7
 *
8
 * @author Oleg Lunegov <[email protected]>
9
 * @link https://github.com/linpax/microphp-framework
10
 * @copyright Copyright (c) 2013 Oleg Lunegov
11
 * @license https://github.com/linpax/microphp-framework/blob/master/LICENSE
12
 * @package Micro
13
 * @subpackage Db
14
 * @version 1.0
15
 * @since 1.0
16
 */
17
abstract class Connection implements IConnection
18
{
19
    private $driver;
20
21
22
    /**
23
     * Make connection to database with PDO driver
24
     *
25
     * @access public
26
     * @param string $dsn DSN connection string
27
     * @param array $config
28
     * @param array $options
29
     */
30
    public function __construct($dsn, $config = [], array $options = [])
0 ignored issues
show
Unused Code introduced by
The parameter $dsn is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $config is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $options is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
31
    {
32
    }
33
34
    /**
35
     * @param $dsn
36
     * @param array $config
37
     * @param array $options
38
     */
39
    public function setDriver($dsn, $config = [], array $options = [])
40
    {
41
        unset($this->driver);
42
43
        $class = '\Micro\Db\Drivers\\' . ucfirst(substr($dsn, 0, strpos($dsn, ':'))) . 'Connection';
44
45
        $this->driver = new $class($dsn, $config, $options);
46
    }
47
48
    /**
49
     * is triggered when invoking inaccessible methods in an object context.
50
     *
51
     * @access public
52
     *
53
     * @param $name string
54
     * @param $arguments array
55
     *
56
     * @return mixed
57
     * @throws \BadMethodCallException
58
     */
59
    public function __call($name, $arguments)
60
    {
61
        if (!method_exists($this->driver, $name)) {
62
            throw new \BadMethodCallException('Method `` not found in connection driver ``');
63
        }
64
65
        return call_user_func_array([$this->driver, $name], $arguments);
66
    }
67
}
68