Completed
Pull Request — master (#361)
by Joas
01:56
created

Version0017Date20191205153154::changeSchema()   C

Complexity

Conditions 8
Paths 128

Size

Total Lines 230

Duplication

Lines 111
Ratio 48.26 %

Importance

Changes 0
Metric Value
dl 111
loc 230
rs 6.5688
c 0
b 0
f 0
cc 8
nc 128
nop 3

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
declare(strict_types=1);
4
5
namespace OCA\Circles\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version0017Date20191205153154 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 */
22
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
23
	}
24
25
	/**
26
	 * @param IOutput $output
27
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
28
	 * @param array $options
29
	 * @return null|ISchemaWrapper
30
	 */
31
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
32
		/** @var ISchemaWrapper $schema */
33
		$schema = $schemaClosure();
34
35 View Code Duplication
		if (!$schema->hasTable('circles_circles')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
36
			$table = $schema->createTable('circles_circles');
37
			$table->addColumn('id', 'integer', [
38
				'autoincrement' => true,
39
				'notnull' => true,
40
				'length' => 4,
41
				'unsigned' => true,
42
			]);
43
			$table->addColumn('unique_id', 'string', [
44
				'notnull' => true,
45
				'length' => 64,
46
			]);
47
			$table->addColumn('name', 'string', [
48
				'notnull' => true,
49
				'length' => 64,
50
			]);
51
			$table->addColumn('description', 'string', [
52
				'notnull' => false,
53
				'length' => 4000,
54
			]);
55
			$table->addColumn('settings', 'string', [
56
				'notnull' => false,
57
				'length' => 4000,
58
			]);
59
			$table->addColumn('type', 'smallint', [
60
				'notnull' => true,
61
				'length' => 2,
62
			]);
63
			$table->addColumn('creation', 'datetime', [
64
				'notnull' => false,
65
			]);
66
			$table->setPrimaryKey(['id']);
67
		}
68
69 View Code Duplication
		if (!$schema->hasTable('circles_members')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
70
			$table = $schema->createTable('circles_members');
71
			$table->addColumn('circle_id', 'string', [
72
				'notnull' => true,
73
				'length' => 64,
74
			]);
75
			$table->addColumn('user_id', 'string', [
76
				'notnull' => true,
77
				'length' => 128,
78
			]);
79
			$table->addColumn('user_type', 'smallint', [
80
				'notnull' => true,
81
				'length' => 1,
82
				'default' => 1,
83
			]);
84
			$table->addColumn('level', 'smallint', [
85
				'notnull' => true,
86
				'length' => 1,
87
			]);
88
			$table->addColumn('status', 'string', [
89
				'notnull' => false,
90
				'length' => 15,
91
			]);
92
			$table->addColumn('note', 'string', [
93
				'notnull' => false,
94
				'length' => 255,
95
			]);
96
			$table->addColumn('joined', 'datetime', [
97
				'notnull' => false,
98
			]);
99
			$table->setPrimaryKey(['circle_id', 'user_id']);
100
		}
101
102 View Code Duplication
		if (!$schema->hasTable('circles_groups')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
103
			$table = $schema->createTable('circles_groups');
104
			$table->addColumn('circle_id', 'string', [
105
				'notnull' => true,
106
				'length' => 64,
107
			]);
108
			$table->addColumn('group_id', 'string', [
109
				'notnull' => true,
110
				'length' => 64,
111
			]);
112
			$table->addColumn('level', 'smallint', [
113
				'notnull' => true,
114
				'length' => 1,
115
			]);
116
			$table->addColumn('note', 'string', [
117
				'notnull' => false,
118
				'length' => 255,
119
			]);
120
			$table->addColumn('joined', 'datetime', [
121
				'notnull' => false,
122
			]);
123
			$table->setPrimaryKey(['circle_id', 'group_id']);
124
		}
125
126 View Code Duplication
		if (!$schema->hasTable('circles_clouds')) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
127
			$table = $schema->createTable('circles_clouds');
128
			$table->addColumn('cloud_id', 'string', [
129
				'notnull' => true,
130
				'length' => 64,
131
			]);
132
			$table->addColumn('address', 'string', [
133
				'notnull' => true,
134
				'length' => 128,
135
			]);
136
			$table->addColumn('status', 'smallint', [
137
				'notnull' => true,
138
				'length' => 1,
139
			]);
140
			$table->addColumn('note', 'string', [
141
				'notnull' => false,
142
				'length' => 255,
143
			]);
144
			$table->addColumn('created', 'datetime', [
145
				'notnull' => false,
146
			]);
147
			$table->setPrimaryKey(['cloud_id']);
148
		}
149
150
		if (!$schema->hasTable('circles_shares')) {
151
			$table = $schema->createTable('circles_shares');
152
			$table->addColumn('id', 'integer', [
153
				'autoincrement' => true,
154
				'notnull' => true,
155
				'length' => 4,
156
				'unsigned' => true,
157
			]);
158
			$table->addColumn('unique_id', 'string', [
159
				'notnull' => false,
160
				'length' => 32,
161
			]);
162
			$table->addColumn('circle_id', 'string', [
163
				'notnull' => true,
164
				'length' => 64,
165
			]);
166
			$table->addColumn('source', 'string', [
167
				'notnull' => true,
168
				'length' => 15,
169
			]);
170
			$table->addColumn('type', 'string', [
171
				'notnull' => true,
172
				'length' => 15,
173
			]);
174
			$table->addColumn('author', 'string', [
175
				'notnull' => true,
176
				'length' => 64,
177
			]);
178
			$table->addColumn('cloud_id', 'string', [
179
				'notnull' => false,
180
				'length' => 128,
181
				'default' => 'null',
182
			]);
183
			$table->addColumn('headers', 'string', [
184
				'notnull' => false,
185
				'length' => 4000,
186
			]);
187
			$table->addColumn('payload', 'string', [
188
				'notnull' => true,
189
				'length' => 4000,
190
			]);
191
			$table->addColumn('creation', 'datetime', [
192
				'notnull' => false,
193
			]);
194
			$table->setPrimaryKey(['id']);
195
		}
196
197
		if (!$schema->hasTable('circles_links')) {
198
			$table = $schema->createTable('circles_links');
199
			$table->addColumn('id', 'smallint', [
200
				'autoincrement' => true,
201
				'notnull' => true,
202
				'length' => 3,
203
				'unsigned' => true,
204
			]);
205
			$table->addColumn('status', 'smallint', [
206
				'notnull' => true,
207
				'length' => 1,
208
			]);
209
			$table->addColumn('circle_id', 'string', [
210
				'notnull' => true,
211
				'length' => 64,
212
			]);
213
			$table->addColumn('unique_id', 'string', [
214
				'notnull' => false,
215
				'length' => 64,
216
			]);
217
			$table->addColumn('address', 'string', [
218
				'notnull' => true,
219
				'length' => 128,
220
			]);
221
			$table->addColumn('token', 'string', [
222
				'notnull' => true,
223
				'length' => 64,
224
			]);
225
			$table->addColumn('key', 'string', [
226
				'notnull' => true,
227
				'length' => 64,
228
			]);
229
			$table->addColumn('creation', 'datetime', [
230
				'notnull' => false,
231
			]);
232
			$table->setPrimaryKey(['id']);
233
		}
234
235
		if (!$schema->hasTable('circles_tokens')) {
236
			$table = $schema->createTable('circles_tokens');
237
			$table->addColumn('circle_id', 'string', [
238
				'notnull' => true,
239
				'length' => 31,
240
			]);
241
			$table->addColumn('user_id', 'string', [
242
				'notnull' => true,
243
				'length' => 255,
244
			]);
245
			$table->addColumn('share_id', 'bigint', [
246
				'notnull' => true,
247
				'length' => 14,
248
			]);
249
			$table->addColumn('token', 'string', [
250
				'notnull' => true,
251
				'length' => 31,
252
			]);
253
			$table->addColumn('password', 'string', [
254
				'notnull' => true,
255
				'length' => 127,
256
			]);
257
			$table->setPrimaryKey(['circle_id', 'user_id', 'share_id']);
258
		}
259
		return $schema;
260
	}
261
262
	/**
263
	 * @param IOutput $output
264
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
265
	 * @param array $options
266
	 */
267
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
268
	}
269
}
270