Version20131225130333_AddItemStudio   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 422
Duplicated Lines 14.69 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 67 1
A down() 62 62 1
A createTableStudio() 0 7 1
B addDataStudio() 0 256 2
A updateItemStudio() 0 23 2

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
class Version20131225130333_AddItemStudio extends AbstractMigration
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
            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_start DATE NOT 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
                NULL,
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
        // create studio table
83
        $this->createTableStudio($schema);
84
        $this->addDataStudio();
85
        $this->updateItemStudio();
86
    }
87
88 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...
89
    {
90
        // create temp table from origin structure
91
        $this->addSql('CREATE TABLE "_new" (
92
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
93
            type VARCHAR(16) DEFAULT NULL,
94
            country VARCHAR(2) DEFAULT NULL,
95
            storage INTEGER DEFAULT NULL,
96
            name VARCHAR(256) NOT NULL,
97
            date_start DATE NOT NULL,
98
            date_end DATE DEFAULT NULL,
99
            duration INTEGER DEFAULT NULL,
100
            summary TEXT DEFAULT NULL,
101
            path VARCHAR(256) DEFAULT NULL,
102
            episodes TEXT DEFAULT NULL,
103
            episodes_number VARCHAR(5) DEFAULT NULL,
104
            translate VARCHAR(256) DEFAULT NULL,
105
            file_info TEXT DEFAULT NULL,
106
            cover VARCHAR(256) DEFAULT NULL,
107
            rating INTEGER DEFAULT NULL,
108
            date_add DATETIME NOT NULL,
109
            date_update DATETIME NOT NULL
110
        )');
111
        $this->addSql('
112
            INSERT INTO
113
                "_new"
114
            SELECT
115
                id,
116
                type,
117
                country,
118
                storage,
119
                name,
120
                date_start,
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
        // drop table
148
        $schema->dropTable('studio');
149
    }
150
151
    protected function createTableStudio(Schema $schema)
0 ignored issues
show
Unused Code introduced by
The parameter $schema is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
152
    {
153
        $this->addSql('CREATE TABLE "studio" (
154
            id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
155
            name VARCHAR(128) NOT NULL
156
        )');
157
    }
158
159
    protected function addDataStudio()
160
    {
161
        // @link http://en.wikipedia.org/wiki/List_of_animation_studios
162
        $studios = [
163
            'A Squared Entertainment',
164
            'A-1 Pictures',
165
            'A. Film',
166
            'A.C.G.T',
167
            'Aardman Animations',
168
            'Ace & Son Moving Picture Co., LLC',
169
            'Act3animation',
170
            'Adelaide Productions',
171
            'AIC',
172
            'Ajia-do',
173
            'AKOM',
174
            'Ánima Estudios',
175
            'Animafilm',
176
            'Animal Logic',
177
            'Animation Collective',
178
            'Animax Entertainment',
179
            'Animonsta Studios',
180
            'Anzovin Studio',
181
            'APPP',
182
            'Arc Productions',
183
            'Arms Corporation',
184
            'Artland',
185
            'Asahi Production',
186
            'Atomic Cartoons',
187
            'Augenblick Studios',
188
            'Bagdasarian Productions',
189
            'Bee Train',
190
            'Bent Image Lab',
191
            'Big Bad Boo',
192
            'Big Idea Productions',
193
            'Blue Sky Studios',
194
            'Blue-Zoo',
195
            'bolexbrothers',
196
            'Bones',
197
            'Boulder Media Limited',
198
            'Brain\'s Base',
199
            'BRB International',
200
            'Brown Bag Films',
201
            'BUG',
202
            'Bullwinkle Studios',
203
            'Buzzco Associates',
204
            'Callicore',
205
            'Cartoon Network Studios',
206
            'Cartoon Pizza/Jumbo Pictures',
207
            'Cartoon Saloon',
208
            'Cellmin Animation Studio',
209
            'Charlex',
210
            'CinéGroupe',
211
            'Clockwork Zoo Animation',
212
            'Collingwood O\'Hare Entertainment',
213
            'Creative Capers Entertainment',
214
            'Creative Power Entertaining',
215
            'Crest Animation Studios',
216
            'Crew972',
217
            'Cuckoo\'s Nest Studio',
218
            'Cuppa Coffee Studio',
219
            'The Curiosity Company',
220
            'Curious Pictures',
221
            'Daume',
222
            'David Production',
223
            'Def2shoot',
224
            'DHX Media',
225
            'Digital Frontier',
226
            'Diomedea',
227
            'DisneyToon Studios',
228
            'Dogakobo',
229
            'Don Bluth Films, Inc.',
230
            'Dong Woo Animation',
231
            'DR Movie',
232
            'DreamWorks Animation',
233
            'Dygra Films',
234
            'Eiken',
235
            'EMation',
236
            'Feel',
237
            'Felix the Cat Productions',
238
            'Film Roman, Inc.',
239
            'Fine Arts Films',
240
            'Folimage',
241
            'Fox Animation Studios',
242
            'Fred Wolf Films Dublin',
243
            'Frederator Studios',
244
            'Future Thought Productions',
245
            'Fuzzy Door Productions',
246
            'Gainax',
247
            'Gallop',
248
            'Global Mechanic',
249
            'GoHands',
250
            'Gonzo',
251
            'GreenFrog Studio',
252
            'Green Gold Animation',
253
            'Guru Studios',
254
            'H5',
255
            'Hanho Heung-Up',
256
            'Head-Gear Animation',
257
            'Hong Ying Animation',
258
            'Ilion Animation Studios',
259
            'Illumination Entertainment',
260
            'Imagi Animation Studios',
261
            'Imagin',
262
            'Industrial Light & Magic',
263
            'J.C.Staff',
264
            'Janimation',
265
            'JibJab',
266
            'John Lemmon Films',
267
            'Kandor Graphics',
268
            'Khara',
269
            'Kharabeesh',
270
            'Kinema Citrus',
271
            'Klasky Csupo',
272
            'Koko Enterprises',
273
            'KRU Studios',
274
            'Kyoto Animation',
275
            'LAIKA',
276
            'Lambie-Nairn',
277
            'Les\' Copaque Production',
278
            'Light Chaser Animation Studios',
279
            'Littlenobody',
280
            'Lucasfilm Animation',
281
            'MAAC India Animation',
282
            'Mac Guff',
283
            'Madhouse',
284
            'Magic Bus',
285
            'Manglobe',
286
            'March Entertainment',
287
            'Marvel Animation Studios',
288
            'Marwah Films & Video Studios',
289
            'Marza Animation Planet',
290
            'Melnitsa Animation Studio',
291
            'Metro-Goldwyn-Mayer Animation',
292
            'Mike Young Productions',
293
            'Millimages',
294
            'Mirari Films',
295
            'Mondo Mini Shows',
296
            'Mondo TV',
297
            'Mook Animation',
298
            'Morphia',
299
            'Mushi Production',
300
            'National Film Board of Canada',
301
            'Nelvana',
302
            'Nickelodeon Animation Studios',
303
            'Nippon Animation',
304
            'Nomad',
305
            'O Entertainment/Omation Animation Studio',
306
            'Oeuvreglobe/Oeuvreglobe Studios',
307
            'Oh! Production',
308
            'OLM, Inc.',
309
            'Ordet',
310
            'Oriental DreamWorks',
311
            'P.A. Works',
312
            'Pacific Data Images',
313
            'PannóniaFilm',
314
            'Paramount Animation',
315
            'Pentamedia Graphics',
316
            'The People\'s Republic of Animation',
317
            'Pierrot',
318
            'Piranha NYC',
319
            'Pixar',
320
            'Plus One Animation',
321
            'Polygon Pictures',
322
            'Post Amazers',
323
            'Powerhouse Animation Studios, Inc.',
324
            'Premavision/Clokey Productions',
325
            'Production I.G',
326
            'Production Reed',
327
            'Radicial Axis',
328
            'Rainbow S.r.l.',
329
            'Rainmaker Digital Effects',
330
            'Reel FX',
331
            'Renegade Animation',
332
            'Rhythm and Hues Studios',
333
            'Richard Williams Animation',
334
            'RingTales',
335
            'Rough Draft Studios',
336
            'Rubicon Group Holding',
337
            'Sae Rom',
338
            'Satelight',
339
            'Sav! The World Productions',
340
            'Savage Studios Ltd.',
341
            'Se-ma-for',
342
            'Seven Arcs',
343
            'Shademaker Productions',
344
            'Shaft',
345
            'Shanghai Animation Film Studio',
346
            'Shin-Ei Animation',
347
            'Silver Link',
348
            'Six Point Harness',
349
            'Škola Animiranog Filma',
350
            'Skycron',
351
            'Smallfilms',
352
            'Sony Pictures Animation',
353
            'Soup2Nuts',
354
            'Soyuzmultfilm',
355
            'Sparx*',
356
            'Spy Pictures',
357
            'Start Anima',
358
            'Stretch Films',
359
            'Studio 4°C',
360
            'Studio Comet',
361
            'Studio DEEN',
362
            'Studio Fantasia',
363
            'Studio Ghibli',
364
            'Studio Gokumi',
365
            'Studio Hibari',
366
            'Studio Mir',
367
            'Sumo Dojo',
368
            'Sunrise',
369
            'Sunwoo Entertainment',
370
            'SynergySP',
371
            'Tatsunoko Productions',
372
            'Teletoon Canada',
373
            'Tezuka Productions',
374
            'Tim Burton Animation Co.',
375
            'Titmouse',
376
            'TMS Entertainment',
377
            'TNK',
378
            'Toei Animation',
379
            'Toon City',
380
            'Toondra',
381
            'Toonz',
382
            'TransTales Entertainment',
383
            'Trigger',
384
            'Triggerfish Animation Studios',
385
            'TYO Animations',
386
            'Ufotable',
387
            'Universal Animation Studios',
388
            'Vanguard Animation',
389
            'Varga Studio',
390
            'Vasoon Animation',
391
            'Walt Disney Animation Studios',
392
            'Walt Disney Television Animation',
393
            'Wang Film Productions',
394
            'Warner Bros. Animation',
395
            'White Fox',
396
            'W!LDBRAIN',
397
            'Williams Street Studios',
398
            'Wit Studio',
399
            'Wizart Animation',
400
            'Worker Studio',
401
            'Xebec',
402
            'Xilam',
403
            'Xyzoo Animation',
404
            'Yowza! Animation',
405
            'Zagreb school of animated films',
406
            'Zexcs',
407
            'Zinkia Entertainment',
408
            'Sharp Image Animation',
409
        ];
410
411
        foreach ($studios as $studio) {
412
            $this->addSql('INSERT INTO "studio" VALUES(NULL, :name)', ['name' => $studio]);
413
        }
414
    }
415
416
    protected function updateItemStudio()
417
    {
418
        $connections = [
419
            ['Ван-Пис', 'Toei Animation'],
420
            ['Самурай Чамплу', 'Manglobe'],
421
            ['Стальной алхимик', 'Bones'],
422
            ['Унесённые призраками', 'Studio Ghibli'],
423
            ['Крутой учитель Онидзука', 'Pierrot'],
424
            ['Бек', 'Madhouse'],
425
            ['Бродяга Кэнсин', 'Studio DEEN'],
426
            ['Мой сосед Тоторо', 'Studio Ghibli'],
427
            ['Хеллсинг', 'Satelight'],
428
            ['Гинтама', 'Sunrise'],
429
            ['Бакуман.', 'J.C.Staff'],
430
            ['Гуррен-Лаганн', 'Gainax'],
431
        ];
432
        foreach ($connections as $connection) {
433
            $this->addSql(
434
                'UPDATE "item" SET studio = (SELECT id FROM studio WHERE name = :studio) WHERE name = :item',
435
                ['item' => $connection[0], 'studio' => $connection[1]]
436
            );
437
        }
438
    }
439
}
440