Test Failed
Push — master ( 7f877f...ed9827 )
by
unknown
01:51
created

TableGateway::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 0 Features 0
Metric Value
c 4
b 0
f 0
dl 0
loc 17
rs 9.4285
cc 3
eloc 10
nc 3
nop 1
1
<?php
2
3
namespace Silk\Database;
4
5
use PhpDocReader\Reader;
6
use Silk\Exceptions\NoTableFoundException;
7
use Zend\Db\TableGateway\AbstractTableGateway;
8
use Zend\Db\TableGateway\Feature\GlobalAdapterFeature;
9
use Silk\Database\AdapterPool;
10
11
/**
12
 * Class TableGateway
13
 * @author  Lucas A. de Araújo <[email protected]>
14
 * @package Silk\Database
15
 */
16
class TableGateway extends AbstractTableGateway
17
{
18
    private $config;
19
20
    public function __construct($object)
21
    {
22
        $this->config = Reader::getConfig($object);
23
24
        if (!array_key_exists('table', $this->config))
25
            throw new NoTableFoundException();
26
27
        $this->table = $this->config['table'];
28
       
29
        if(!isset($this->config['adapter']))
30
            $this->config['adapter'] = 'Default';
31
        
32
        $adapterPool = new AdapterPool();
33
        $this->adapter = $adapterPool->get($this->config['adapter']);
34
35
        $this->updateContext();
36
    }
37
38
    protected function updateContext()
39
    {
40
        $platform = $this->adapter->getPlatform()->getName();
41
        
42 View Code Duplication
        if(isset($this->config['schema']) && $platform == 'MySQL'){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
43
            $sql = 'USE ' . $this->config['schema'] . ';';
44
            $this->adapter->getDriver()->getConnection()->execute($sql);
45
        }
46
        
47 View Code Duplication
        if(isset($this->config['schema']) && $platform == 'PostgreSQL'){
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
            $sql = 'SET SCHEMA \'' . $this->config['schema'] . '\';';
49
            $this->adapter->getDriver()->getConnection()->execute($sql);
50
        }
51
    }
52
}
53