Version20180804082737   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 226
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 0
loc 226
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A up() 0 18 3
A down() 0 6 1
B getGenresJson() 0 197 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace DoctrineMigrations;
6
7
use Doctrine\DBAL\Schema\Schema;
8
use Doctrine\Migrations\AbstractMigration;
9
10
final class Version20180804082737 extends AbstractMigration
11
{
12
    public function up(Schema $schema): void
13
    {
14
        $pass = '';
15
        $roles = '["ROLE_USER","ROLE_ADMIN"]';
16
        $this->addSql("INSERT INTO users_profiles (id, first_name, last_name, birth_date, about, public_email) VALUES (1, 'Support', 'Support', NULL, NULL, '[email protected]')");
17
        $this->addSql("INSERT INTO users (id, profile_id, email, is_email_confirmed, username, password, roles) VALUES (1, 1, '[email protected]', 1, 'support', '$pass', '$roles')");
18
19
        $genresJson = $this->getGenresJson();
20
        $genres = json_decode($genresJson, true);
21
22
        foreach ($genres as $genre) {
23
            $this->addSql("INSERT INTO genres (id, tmdb_id) VALUES (NEXTVAL('genres_id_seq'), {$genre['id']})");
24
25
            foreach ($genre['translations'] as $locale => $name) {
26
                $this->addSql("INSERT INTO genres_translations (id, genre_id, locale, \"name\") VALUES (NEXTVAL('genres_translations_id_seq'), CURRVAL('genres_id_seq'), '$locale', '$name')");
27
            }
28
        }
29
    }
30
31
    public function down(Schema $schema): void
32
    {
33
        $this->addSql('DELETE FROM users WHERE id = 1');
34
        $this->addSql('DELETE FROM users_profiles WHERE id = 1');
35
        $this->addSql('DELETE FROM genres WHERE tmdb_id > 0');
36
    }
37
38
    private function getGenresJson(): string
39
    {
40
        return <<<JSON
41
[
42
  {
43
    "id": 28,
44
    "name": "Action",
45
    "translations": {
46
      "en": "Action",
47
      "ru": "Экшн",
48
      "uk": "Екшн",
49
      "pl": "Action"
50
    }
51
  },
52
  {
53
    "id": 12,
54
    "name": "Adventure",
55
    "translations": {
56
      "en": "Adventure",
57
      "ru": "Приключения",
58
      "uk": "Пригоди",
59
      "pl": "Adventure"
60
    }
61
  },
62
  {
63
    "id": 16,
64
    "name": "Animation",
65
    "translations": {
66
      "en": "Animation",
67
      "ru": "Анимация",
68
      "uk": "Анімація",
69
      "pl": "Animation"
70
    }
71
  },
72
  {
73
    "id": 35,
74
    "name": "Comedy",
75
    "translations": {
76
      "en": "Comedy",
77
      "ru": "Комедия",
78
      "uk": "Комедія",
79
      "pl": "Comedy"
80
    }
81
  },
82
  {
83
    "id": 80,
84
    "name": "Crime",
85
    "translations": {
86
      "en": "Crime",
87
      "ru": "Криминальный",
88
      "uk": "Кримінальний",
89
      "pl": "Crime"
90
    }
91
  },
92
  {
93
    "id": 99,
94
    "name": "Documentary",
95
    "translations": {
96
      "en": "Documentary",
97
      "ru": "Документальный",
98
      "uk": "Документальний",
99
      "pl": "Documentary"
100
    }
101
  },
102
  {
103
    "id": 18,
104
    "name": "Drama",
105
    "translations": {
106
      "en": "Drama",
107
      "ru": "Драма",
108
      "uk": "Драма",
109
      "pl": "Drama"
110
    }
111
  },
112
  {
113
    "id": 10751,
114
    "name": "Family",
115
    "translations": {
116
      "en": "Family",
117
      "ru": "Семейный",
118
      "uk": "Сімейний",
119
      "pl": "Family"
120
    }
121
  },
122
  {
123
    "id": 14,
124
    "name": "Fantasy",
125
    "translations": {
126
      "en": "Fantasy",
127
      "ru": "Фэнтези",
128
      "uk": "Фентезі",
129
      "pl": "Fantasy"
130
    }
131
  },
132
  {
133
    "id": 36,
134
    "name": "History",
135
    "translations": {
136
      "en": "History",
137
      "ru": "Исторический",
138
      "uk": "Історичний",
139
      "pl": "History"
140
    }
141
  },
142
  {
143
    "id": 27,
144
    "name": "Horror",
145
    "translations": {
146
      "en": "Horror",
147
      "ru": "Ужасы",
148
      "uk": "Жахи",
149
      "pl": "Horror"
150
    }
151
  },
152
  {
153
    "id": 10402,
154
    "name": "Music",
155
    "translations": {
156
      "en": "Music",
157
      "ru": "Мюзикл",
158
      "uk": "Мюзікл",
159
      "pl": "Music"
160
    }
161
  },
162
  {
163
    "id": 9648,
164
    "name": "Mystery",
165
    "translations": {
166
      "en": "Mystery",
167
      "ru": "Мистика",
168
      "uk": "Містика",
169
      "pl": "Mystery"
170
    }
171
  },
172
  {
173
    "id": 10749,
174
    "name": "Romance",
175
    "translations": {
176
      "en": "Romance",
177
      "ru": "Роман",
178
      "uk": "Роман",
179
      "pl": "Romance"
180
    }
181
  },
182
  {
183
    "id": 878,
184
    "name": "Science Fiction",
185
    "translations": {
186
      "en": "Science Fiction",
187
      "ru": "Научно-популярный",
188
      "uk": "Науково-популярний",
189
      "pl": "Science Fiction"
190
    }
191
  },
192
  {
193
    "id": 10770,
194
    "name": "TV Movie",
195
    "translations": {
196
      "en": "TV Movie",
197
      "ru": "Телесериал",
198
      "uk": "Телесеріал",
199
      "pl": "TV Movie"
200
    }
201
  },
202
  {
203
    "id": 53,
204
    "name": "Thriller",
205
    "translations": {
206
      "en": "Thriller",
207
      "ru": "Триллер",
208
      "uk": "Триллер",
209
      "pl": "Thriller"
210
    }
211
  },
212
  {
213
    "id": 10752,
214
    "name": "War",
215
    "translations": {
216
      "en": "War",
217
      "ru": "Военный",
218
      "uk": "Військовий",
219
      "pl": "War"
220
    }
221
  },
222
  {
223
    "id": 37,
224
    "name": "Western",
225
    "translations": {
226
      "en": "Western",
227
      "ru": "Вестерн",
228
      "uk": "Вестерн",
229
      "pl": "Western"
230
    }
231
  }
232
]
233
JSON;
234
    }
235
}
236