up()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 62
Code Lines 11

Duplication

Lines 62
Ratio 100 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 62
loc 62
rs 9.4743
cc 1
eloc 11
nc 1
nop 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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
10
namespace AnimeDb\Bundle\CatalogBundle\DoctrineMigrations;
11
12
use Doctrine\DBAL\Migrations\AbstractMigration;
13
use Doctrine\DBAL\Schema\Schema;
14
15
/**
16
 * Auto-generated Migration: Please modify to your needs!
17
 */
18
class Version20140122122107_RenameItemDateStartToDatePremiere extends AbstractMigration
19
{
20 View Code Duplication
    public function up(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
21
    {
22
        // create temp table from new structure
23
        $this->addSql('CREATE TABLE "_new" (
24
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
25
            type VARCHAR(16) DEFAULT NULL,
26
            country VARCHAR(2) DEFAULT NULL,
27
            storage INTEGER DEFAULT NULL,
28
            studio INTEGER DEFAULT NULL,
29
            name VARCHAR(256) NOT NULL,
30
            date_premiere DATE DEFAULT NULL,
31
            date_end DATE DEFAULT NULL,
32
            duration INTEGER DEFAULT NULL,
33
            summary TEXT DEFAULT NULL,
34
            path VARCHAR(256) DEFAULT NULL,
35
            episodes TEXT DEFAULT NULL,
36
            episodes_number VARCHAR(5) DEFAULT NULL,
37
            translate VARCHAR(256) DEFAULT NULL,
38
            file_info TEXT DEFAULT NULL,
39
            cover VARCHAR(256) DEFAULT NULL,
40
            rating INTEGER DEFAULT NULL,
41
            date_add DATETIME NOT NULL,
42
            date_update DATETIME NOT NULL
43
        )');
44
        $this->addSql('
45
            INSERT INTO
46
                "_new"
47
            SELECT
48
                id,
49
                type,
50
                country,
51
                storage,
52
                studio,
53
                name,
54
                date_start,
55
                date_end,
56
                duration,
57
                summary,
58
                path,
59
                episodes,
60
                episodes_number,
61
                translate,
62
                file_info,
63
                cover,
64
                rating,
65
                date_add,
66
                date_update
67
            FROM
68
                "item"
69
        ');
70
        // rename new to origin and drop origin
71
        $this->addSql('ALTER TABLE item RENAME TO _origin');
72
        $this->addSql('ALTER TABLE _new RENAME TO item');
73
        $this->addSql('DROP TABLE _origin');
74
75
        // create index
76
        $this->addSql('CREATE INDEX item_country_idx ON item (country);');
77
        $this->addSql('CREATE INDEX item_storage_idx ON item (storage);');
78
        $this->addSql('CREATE INDEX item_type_idx ON item (type)');
79
        $this->addSql('CREATE INDEX item_rating_idx ON item (rating)');
80
        $this->addSql('CREATE INDEX item_studio_idx ON item (studio)');
81
    }
82
83 View Code Duplication
    public function down(Schema $schema)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
84
    {
85
        // create temp table from origin structure
86
        $this->addSql('CREATE TABLE "_new" (
87
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
88
            type VARCHAR(16) DEFAULT NULL,
89
            country VARCHAR(2) DEFAULT NULL,
90
            storage INTEGER DEFAULT NULL,
91
            studio INTEGER DEFAULT NULL,
92
            name VARCHAR(256) NOT NULL,
93
            date_start DATE NOT NULL,
94
            date_end DATE DEFAULT NULL,
95
            duration INTEGER DEFAULT NULL,
96
            summary TEXT DEFAULT NULL,
97
            path VARCHAR(256) DEFAULT NULL,
98
            episodes TEXT DEFAULT NULL,
99
            episodes_number VARCHAR(5) DEFAULT NULL,
100
            translate VARCHAR(256) DEFAULT NULL,
101
            file_info TEXT DEFAULT NULL,
102
            cover VARCHAR(256) DEFAULT NULL,
103
            rating INTEGER DEFAULT NULL,
104
            date_add DATETIME NOT NULL,
105
            date_update DATETIME NOT NULL
106
        )');
107
        $this->addSql('
108
            INSERT INTO
109
                "_new"
110
            SELECT
111
                id,
112
                type,
113
                country,
114
                storage,
115
                studio,
116
                name,
117
                CASE WHEN date_premiere IS NOT NULL
118
                THEN date_premiere
119
                ELSE "'.date('Y-m-d H:i:s').'"
120
                END,
121
                date_end,
122
                duration,
123
                summary,
124
                path,
125
                episodes,
126
                episodes_number,
127
                translate,
128
                file_info,
129
                cover,
130
                rating,
131
                date_add,
132
                date_update
133
            FROM
134
                "item"
135
        ');
136
        // rename new to origin and drop origin
137
        $this->addSql('ALTER TABLE item RENAME TO _origin');
138
        $this->addSql('ALTER TABLE _new RENAME TO item');
139
        $this->addSql('DROP TABLE _origin');
140
141
        // create index
142
        $this->addSql('CREATE INDEX item_country_idx ON item (country);');
143
        $this->addSql('CREATE INDEX item_storage_idx ON item (storage);');
144
        $this->addSql('CREATE INDEX item_type_idx ON item (type)');
145
        $this->addSql('CREATE INDEX item_rating_idx ON item (rating)');
146
    }
147
}
148