Test Setup Failed
Push — master ( d6fde7...1e848b )
by Php Easy Api
04:20
created

Mysql   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 35
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A getConnection() 0 3 1
1
<?php
2
3
namespace Migratio\Connector;
4
5
use Migratio\GrammarStructure\Mysql\QueryBase;
6
7
class Mysql extends QueryBase
8
{
9
    /**
10
     * @var $instance
0 ignored issues
show
Documentation Bug introduced by
The doc comment $instance at position 0 could not be parsed: Unknown type name '$instance' at position 0 in $instance.
Loading history...
11
     */
12
    private static $instance;
13
14
    /**
15
     * @var $connection
0 ignored issues
show
Documentation Bug introduced by
The doc comment $connection at position 0 could not be parsed: Unknown type name '$connection' at position 0 in $connection.
Loading history...
16
     */
17
    protected $connection;
18
19
    /**
20
     * Mysql constructor.
21
     * @param $config
22
     */
23
    public function __construct($config)
24
    {
25
        if(is_null(self::$instance)){
26
27
            //get pdo dsn
28
            $dsn=''.$config['driver'].':host='.$config['host'].';dbname='.$config['database'].'';
29
            $this->connection = new \PDO($dsn, $config['user'], $config['password']);
30
            $this->connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
31
32
            self::$instance=true;
33
        }
34
    }
35
36
    /**
37
     * @return \PDO
38
     */
39
    public function getConnection()
40
    {
41
        return $this->connection;
42
    }
43
44
}