Version20131223134044_AddNoticeDateStart   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 60
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 0
cbo 1
dl 60
loc 60
c 0
b 0
f 0
ccs 0
cts 49
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B down() 27 27 1
B up() 29 29 1

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
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
namespace AnimeDb\Bundle\AppBundle\DoctrineMigrations;
10
11
use Doctrine\DBAL\Migrations\AbstractMigration;
12
use Doctrine\DBAL\Schema\Schema;
13
14 View Code Duplication
class Version20131223134044_AddNoticeDateStart extends AbstractMigration
15
{
16
    public function up(Schema $schema)
17
    {
18
        // create temp table from new structure
19
        $this->addSql('CREATE TABLE "_new" (
20
            id INTEGER NOT NULL,
21
            message TEXT NOT NULL,
22
            date_closed DATETIME DEFAULT NULL,
23
            date_created DATETIME NOT NULL,
24
            date_start DATETIME NOT NULL,
25
            lifetime INTEGER NOT NULL,
26
            status INTEGER NOT NULL,
27
            PRIMARY KEY(id)
28
        )');
29
30
        $this->addSql('
31
            INSERT INTO
32
                "_new"
33
            SELECT
34
                id, message, date_closed, date_created, date_created, lifetime, status
35
            FROM
36
                "notice"
37
        ');
38
        // rename new to origin and drop origin
39
        $this->addSql('ALTER TABLE notice RENAME TO _origin');
40
        $this->addSql('ALTER TABLE _new RENAME TO notice');
41
        $this->addSql('DROP TABLE _origin');
42
43
        $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_start)');
44
    }
45
46
    public function down(Schema $schema)
47
    {
48
        // create temp table from origin structure
49
        $this->addSql('CREATE TABLE "_new" (
50
            id INTEGER NOT NULL,
51
            message TEXT NOT NULL,
52
            date_closed DATETIME DEFAULT NULL,
53
            date_created DATETIME NOT NULL,
54
            lifetime INTEGER NOT NULL,
55
            status INTEGER NOT NULL,
56
            PRIMARY KEY(id)
57
        )');
58
        $this->addSql('
59
            INSERT INTO
60
                "_new"
61
            SELECT
62
                id, message, date_closed, date_created, lifetime, status
63
            FROM
64
                "notice"
65
        ');
66
        // rename new to origin and drop origin
67
        $this->addSql('ALTER TABLE notice RENAME TO _origin');
68
        $this->addSql('ALTER TABLE _new RENAME TO notice');
69
        $this->addSql('DROP TABLE _origin');
70
71
        $this->addSql('CREATE INDEX notice_show_idx ON notice (date_closed, date_created)');
72
    }
73
}
74