Version20140117113408_StorageDescriptionIsNotRequired   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 66
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 2
c 0
b 0
f 0
lcom 0
cbo 1
dl 66
loc 66
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B up() 27 27 1
B down() 35 35 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
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 View Code Duplication
class Version20140117113408_StorageDescriptionIsNotRequired extends AbstractMigration
0 ignored issues
show
Duplication introduced by
This class 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...
19
{
20
    public function up(Schema $schema)
21
    {
22
        // create temp table from new structure
23
        $this->addSql('CREATE TABLE "_new" (
24
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
25
            name VARCHAR(128) NOT NULL,
26
            description TEXT DEFAULT NULL,
27
            type VARCHAR(16) NOT NULL,
28
            path TEXT DEFAULT NULL,
29
            modified DATE DEFAULT NULL
30
        )');
31
32
        $this->addSql('
33
            INSERT INTO
34
                "_new"
35
            SELECT
36
                id, name, description, type, path, modified
37
            FROM
38
                "storage"
39
        ');
40
        // rename new to origin and drop origin
41
        $this->addSql('ALTER TABLE storage RENAME TO _origin');
42
        $this->addSql('ALTER TABLE _new RENAME TO storage');
43
        $this->addSql('DROP TABLE _origin');
44
45
        $this->addSql('CREATE INDEX storage_type_idx ON storage (type)');
46
    }
47
48
    public function down(Schema $schema)
49
    {
50
        // create temp table from origin structure
51
        $this->addSql('CREATE TABLE "_new" (
52
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
53
            name VARCHAR(128) NOT NULL,
54
            description TEXT NOT NULL,
55
            type VARCHAR(16) NOT NULL,
56
            path TEXT DEFAULT NULL,
57
            modified DATE DEFAULT NULL
58
        )');
59
60
        $this->addSql('
61
            INSERT INTO
62
                "_new"
63
            SELECT
64
                id,
65
                name,
66
                CASE WHEN description IS NOT NULL
67
                THEN description
68
                ELSE ""
69
                END,
70
                type,
71
                path,
72
                modified
73
            FROM
74
                "storage"
75
        ');
76
        // rename new to origin and drop origin
77
        $this->addSql('ALTER TABLE storage RENAME TO _origin');
78
        $this->addSql('ALTER TABLE _new RENAME TO storage');
79
        $this->addSql('DROP TABLE _origin');
80
81
        $this->addSql('CREATE INDEX storage_type_idx ON storage (type)');
82
    }
83
}
84