Test Failed
Push — master ( ed9827...cb7f9b )
by
unknown
01:45
created

src/Silk/Database/TableGateway.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

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
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
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