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

TableGateway   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 37
Duplicated Lines 21.62 %

Coupling/Cohesion

Components 1
Dependencies 7

Importance

Changes 4
Bugs 0 Features 0
Metric Value
wmc 8
c 4
b 0
f 0
lcom 1
cbo 7
dl 8
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 17 3
B updateContext() 8 14 5

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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