Completed
Push — master ( 36054f...7ebd4b )
by Jeremy
17s
created

WallabagMigration   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
c 1
b 0
f 0
lcom 1
cbo 4
dl 0
loc 40
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 3 1
A down() 0 3 1
A setContainer() 0 4 1
A getTable() 0 16 3
1
<?php
2
3
namespace Wallabag\CoreBundle\Doctrine;
4
5
use Doctrine\DBAL\Migrations\AbstractMigration;
6
use Doctrine\DBAL\Schema\Schema;
7
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
8
use Symfony\Component\DependencyInjection\ContainerInterface;
9
10
abstract class WallabagMigration extends AbstractMigration implements ContainerAwareInterface
11
{
12
    const UN_ESCAPED_TABLE = true;
13
14
    /**
15
     * @var ContainerInterface
16
     */
17
    protected $container;
18
19
    // because there are declared as abstract in `AbstractMigration` we need to delarer here too
20
    public function up(Schema $schema)
21
    {
22
    }
23
24
    public function down(Schema $schema)
25
    {
26
    }
27
28
    public function setContainer(ContainerInterface $container = null)
29
    {
30
        $this->container = $container;
31
    }
32
33
    protected function getTable($tableName, $unEscaped = false)
34
    {
35
        $table = $this->container->getParameter('database_table_prefix') . $tableName;
36
37
        if (self::UN_ESCAPED_TABLE === $unEscaped) {
38
            return $table;
39
        }
40
41
        // escape table name is handled using " on postgresql
42
        if ('postgresql' === $this->connection->getDatabasePlatform()->getName()) {
43
            return '"' . $table . '"';
44
        }
45
46
        // return escaped table
47
        return '`' . $table . '`';
48
    }
49
}
50