Completed
Pull Request — master (#362)
by Maxence
01:55 queued 11s
created

Version0017Date20191210153032::changeSchema()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 129

Duplication

Lines 39
Ratio 30.23 %

Importance

Changes 0
Metric Value
dl 39
loc 129
rs 8
c 0
b 0
f 0
cc 4
nc 8
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 declare(strict_types=1);
2
3
4
/**
5
 * Circles - Bring cloud-users closer together.
6
 *
7
 * This file is licensed under the Affero General Public License version 3 or
8
 * later. See the COPYING file.
9
 *
10
 * @author Maxence Lange <[email protected]>
11
 * @copyright 2019
12
 * @license GNU AGPL version 3 or any later version
13
 *
14
 * This program is free software: you can redistribute it and/or modify
15
 * it under the terms of the GNU Affero General Public License as
16
 * published by the Free Software Foundation, either version 3 of the
17
 * License, or (at your option) any later version.
18
 *
19
 * This program is distributed in the hope that it will be useful,
20
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22
 * GNU Affero General Public License for more details.
23
 *
24
 * You should have received a copy of the GNU Affero General Public License
25
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
26
 *
27
 */
28
29
30
namespace OCA\Circles\Migration;
31
32
33
use Closure;
34
use Doctrine\DBAL\Schema\SchemaException;
35
use OCP\DB\ISchemaWrapper;
36
use OCP\Migration\IOutput;
37
use OCP\Migration\SimpleMigrationStep;
38
39
40
class Version0017Date20191210153032 extends SimpleMigrationStep {
41
42
	/**
43
	 * @param IOutput $output
44
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
45
	 * @param array $options
46
	 */
47
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
48
	}
49
50
	/**
51
	 * @param IOutput $output
52
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
53
	 * @param array $options
54
	 *
55
	 * @return null|ISchemaWrapper
56
	 * @throws SchemaException
57
	 */
58
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
59
		/** @var ISchemaWrapper $schema */
60
		$schema = $schemaClosure();
61
62 View Code Duplication
		if (!$schema->hasTable('circles_gsevents')) {
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...
63
			$table = $schema->createTable('circles_gsevents');
64
			$table->addColumn(
65
				'token', 'string', [
66
						   'notnull' => false,
67
						   'length'  => 63,
68
					   ]
69
			);
70
			$table->addColumn(
71
				'event', 'text', [
72
						   'notnull' => false
73
					   ]
74
			);
75
			$table->addColumn(
76
				'instance', 'string', [
77
							  'length'  => 255,
78
							  'notnull' => false
79
						  ]
80
			);
81
			$table->addColumn(
82
				'severity', 'integer', [
83
							  'length'  => 3,
84
							  'notnull' => false
85
						  ]
86
			);
87
			$table->addColumn(
88
				'status', 'integer', [
89
							'length'  => 3,
90
							'notnull' => false
91
						]
92
			);
93
			$table->addColumn(
94
				'creation', 'bigint', [
95
							  'length'  => 14,
96
							  'notnull' => false
97
						  ]
98
			);
99
			$table->addUniqueIndex(['token', 'instance']);
100
		}
101
102
		if (!$schema->hasTable('circles_gsshares')) {
103
			$table = $schema->createTable('circles_gsshares');
104
			$table->addColumn(
105
				'id', 'integer', [
106
						'notnull'       => false,
107
						'length'        => 11,
108
						'autoincrement' => true,
109
						'unsigned'      => true
110
					]
111
			);
112
			$table->addColumn(
113
				'circle_id', 'string', [
114
							   'length'  => 15,
115
							   'notnull' => false
116
						   ]
117
			);
118
			$table->addColumn(
119
				'owner', 'string', [
120
						   'length'  => 15,
121
						   'notnull' => false
122
					   ]
123
			);
124
			$table->addColumn(
125
				'instance', 'string', [
126
							  'length'  => 255,
127
							  'notnull' => false
128
						  ]
129
			);
130
			$table->addColumn(
131
				'token', 'string', [
132
						   'notnull' => false,
133
						   'length'  => 63
134
					   ]
135
			);
136
			$table->addColumn(
137
				'parent', 'integer', [
138
							'notnull' => false,
139
							'length'  => 11,
140
						]
141
			);
142
			$table->addColumn(
143
				'mountpoint', 'text', [
144
								'notnull' => false
145
							]
146
			);
147
			$table->addColumn(
148
				'mountpoint_hash', 'string', [
149
									 'length'  => 64,
150
									 'notnull' => false
151
								 ]
152
			);
153
			$table->setPrimaryKey(['id']);
154
			$table->addUniqueIndex(['circle_id', 'mountpoint_hash']);
155
		}
156
157
		if (!$schema->hasTable('circles_gsshares_mp')) {
158
			$table = $schema->createTable('circles_gsshares_mp');
159
			$table->addColumn(
160
				'share_id', 'integer', [
161
							  'length'  => 11,
162
							  'notnull' => false
163
						  ]
164
			);
165
			$table->addColumn(
166
				'user_id', 'string', [
167
							 'length'  => 127,
168
							 'notnull' => false
169
						 ]
170
			);
171
			$table->addColumn(
172
				'mountpoint', 'text', [
173
								'notnull' => false
174
							]
175
			);
176
			$table->addColumn(
177
				'mountpoint_hash', 'string', [
178
									 'length'  => 64,
179
									 'notnull' => false
180
								 ]
181
			);
182
			$table->setPrimaryKey(['share_id', 'user_id']);
183
		}
184
185
		return $schema;
186
	}
187
188
189
	/**
190
	 * @param IOutput $output
191
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
192
	 * @param array $options
193
	 */
194
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
195
	}
196
197
}
198
199