Completed
Pull Request — master (#362)
by Maxence
01:56
created

Version0017Date20191210153032::changeSchema()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 56

Duplication

Lines 10
Ratio 17.86 %

Importance

Changes 0
Metric Value
dl 10
loc 56
rs 8.9599
c 0
b 0
f 0
cc 2
nc 2
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
		$table = $schema->getTable('circles_members');
63 View Code Duplication
		if (!$table->hasColumn('instance')) {
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...
64
			$table->addColumn(
65
				'instance', 'string', [
66
							  'notnull' => false,
67
							  'length'  => 255,
68
						  ]
69
			);
70
			$table->dropPrimaryKey();
71
			$table->setPrimaryKey(['circle_id', 'user_id', 'user_type', 'instance']);
72
		}
73
74
		$table = $schema->createTable('circles_gsevents');
75
		$table->addColumn(
76
			'token', 'string', [
77
					   'notnull' => false,
78
					   'length'  => 63,
79
				   ]
80
		);
81
		$table->addColumn(
82
			'event', 'text', [
83
					   'notnull' => false
84
				   ]
85
		);
86
		$table->addColumn(
87
			'instance', 'string', [
88
						  'length'  => 255,
89
						  'notnull' => false
90
					  ]
91
		);
92
		$table->addColumn(
93
			'severity', 'integer', [
94
						  'length'  => 3,
95
						  'notnull' => false
96
					  ]
97
		);
98
		$table->addColumn(
99
			'status', 'integer', [
100
						'length'  => 3,
101
						'notnull' => false
102
					]
103
		);
104
		$table->addColumn(
105
			'creation', 'bigint', [
106
						  'length'  => 14,
107
						  'notnull' => false
108
					  ]
109
		);
110
		$table->addUniqueIndex(['token', 'instance']);
111
112
		return $schema;
113
	}
114
115
	/**
116
	 * @param IOutput $output
117
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
118
	 * @param array $options
119
	 */
120
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
121
	}
122
123
}
124
125