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

TableGateway::updateContext()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 14
Code Lines 8

Duplication

Lines 8
Ratio 57.14 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 8
loc 14
rs 8.8571
cc 5
eloc 8
nc 4
nop 0
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