Completed
Pull Request — master (#544)
by Maxence
02:26
created

Version0021Date20210105123456::changeSchema()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 51

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 51
rs 9.069
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
2
3
declare(strict_types=1);
4
5
/**
6
 * Circles - Bring cloud-users closer together.
7
 *
8
 * This file is licensed under the Affero General Public License version 3 or
9
 * later. See the COPYING file.
10
 *
11
 * @author Maxence Lange <[email protected]>
12
 * @copyright 2019
13
 * @license GNU AGPL version 3 or any later version
14
 *
15
 * This program is free software: you can redistribute it and/or modify
16
 * it under the terms of the GNU Affero General Public License as
17
 * published by the Free Software Foundation, either version 3 of the
18
 * License, or (at your option) any later version.
19
 *
20
 * This program is distributed in the hope that it will be useful,
21
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
 * GNU Affero General Public License for more details.
24
 *
25
 * You should have received a copy of the GNU Affero General Public License
26
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
27
 *
28
 */
29
30
namespace OCA\Circles\Migration;
31
32
use Closure;
33
use OCP\DB\ISchemaWrapper;
34
use OCP\IDBConnection;
35
use OCP\Migration\IOutput;
36
use OCP\Migration\SimpleMigrationStep;
37
38
39
/**
40
 * Class Version0021Date20210105123456
41
 *
42
 * @package OCA\Circles\Migration
43
 */
44
class Version0021Date20210105123456 extends SimpleMigrationStep {
45
46
47
	/** @var IDBConnection */
48
	private $connection;
49
50
51
	/**
52
	 * @param IDBConnection $connection
53
	 */
54
	public function __construct(IDBConnection $connection) {
55
		$this->connection = $connection;
56
	}
57
58
59
	/**
60
	 * @param IOutput $output
61
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
62
	 * @param array $options
63
	 *
64
	 * @return null|ISchemaWrapper
65
	 */
66
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
67
		/** @var ISchemaWrapper $schema */
68
		$schema = $schemaClosure();
69
70
		if (!$schema->hasTable('circle_remote')) {
71
			$table = $schema->createTable('circle_remote');
72
			$table->addColumn(
73
				'id', 'integer', [
74
						'autoincrement' => true,
75
						'notnull'       => true,
76
						'length'        => 4,
77
						'unsigned'      => true,
78
					]
79
			);
80
			$table->addColumn(
81
				'uid', 'string', [
82
						 'notnull' => false,
83
						 'length'  => 20,
84
					 ]
85
			);
86
			$table->addColumn(
87
				'instance', 'string', [
88
							  'notnull' => false,
89
							  'length'  => 127,
90
						  ]
91
			);
92
			$table->addColumn(
93
				'href', 'string', [
94
						  'notnull' => false,
95
						  'length'  => 254,
96
					  ]
97
			);
98
			$table->addColumn(
99
				'item', 'text', [
100
						  'notnull' => false,
101
					  ]
102
			);
103
			$table->addColumn(
104
				'creation', 'datetime', [
105
							  'notnull' => false,
106
						  ]
107
			);
108
109
			$table->setPrimaryKey(['id']);
110
			$table->addUniqueIndex(['instance']);
111
			$table->addIndex(['uid']);
112
			$table->addIndex(['href']);
113
		}
114
115
		return $schema;
116
	}
117
118
119
}
120