Completed
Pull Request — master (#347)
by Maxence
02:20
created

Version0017Date20191206144441::changeSchema()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 71

Duplication

Lines 40
Ratio 56.34 %

Importance

Changes 0
Metric Value
dl 40
loc 71
rs 7.2016
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
 * Circles - Bring cloud-users closer together.
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Maxence Lange <[email protected]>
9
 * @copyright 2019
10
 * @license GNU AGPL version 3 or any later version
11
 *
12
 * This program is free software: you can redistribute it and/or modify
13
 * it under the terms of the GNU Affero General Public License as
14
 * published by the Free Software Foundation, either version 3 of the
15
 * License, or (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20
 * GNU Affero General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Affero General Public License
23
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
24
 *
25
 */
26
27
declare(strict_types=1);
28
29
namespace OCA\Circles\Migration;
30
31
use Closure;
32
use Doctrine\DBAL\Schema\SchemaException;
33
use Doctrine\DBAL\Types\Type;
34
use OCP\DB\ISchemaWrapper;
35
use OCP\Migration\IOutput;
36
use OCP\Migration\SimpleMigrationStep;
37
38
/**
39
 * Auto-generated migration step: Please modify to your needs!
40
 */
41
class Version0017Date20191206144441 extends SimpleMigrationStep {
42
43
	/**
44
	 * @param IOutput $output
45
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
46
	 * @param array $options
47
	 */
48
	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
49
	}
50
51
	/**
52
	 * @param IOutput $output
53
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
54
	 * @param array $options
55
	 *
56
	 * @return null|ISchemaWrapper
57
	 * @throws SchemaException
58
	 */
59
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
60
		/** @var ISchemaWrapper $schema */
61
		$schema = $schemaClosure();
62
63
		$table = $schema->getTable('circles_circles');
64
		if (!$table->hasColumn('contact_addressbook')) {
65
			$table->addColumn(
66
				'contact_addressbook', 'integer', [
67
										 'notnull'  => false,
68
										 'unsigned' => true,
69
										 'length'   => 7,
70
									 ]
71
			);
72
		}
73 View Code Duplication
		if (!$table->hasColumn('contact_groupname')) {
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...
74
			$table->addColumn(
75
				'contact_groupname', 'string', [
76
									   'notnull' => false,
77
									   'length'  => 127,
78
								   ]
79
			);
80
		}
81
82
		$table = $schema->getTable('circles_members');
83 View Code Duplication
		if (!$table->hasColumn('contact_meta')) {
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...
84
			$table->addColumn(
85
				'contact_meta', 'string', [
86
								  'notnull' => false,
87
								  'length'  => 1000,
88
							  ]
89
			);
90
		}
91 View Code Duplication
		if (!$table->hasColumn('contact_checked')) {
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...
92
			$table->addColumn(
93
				'contact_checked', Type::SMALLINT, [
94
								  'notnull' => false,
95
								  'length'  => 1,
96
							  ]
97
			);
98
		}
99
		if (!$table->hasColumn('contact_id')) {
100
			$table->addColumn(
101
				'contact_id', 'string', [
102
								'notnull' => false,
103
								'length'  => 127,
104
							]
105
			);
106
			$table->dropPrimaryKey();
107
			$table->setPrimaryKey(['circle_id', 'user_id', 'contact_id']);
108
		}
109
110
		$table = $schema->getTable('circles_tokens');
111 View Code Duplication
		if (!$table->hasColumn('orig_password')) {
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...
112
			$table->addColumn(
113
				'orig_password', 'string', [
114
								  'notnull' => false,
115
								  'length'  => 255,
116
							  ]
117
			);
118
		}
119 View Code Duplication
		if (!$table->hasColumn('accepted')) {
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...
120
			$table->addColumn(
121
				'accepted', Type::SMALLINT, [
122
								   'notnull' => false,
123
								   'length'  => 1,
124
							   ]
125
			);
126
		}
127
128
		return $schema;
129
	}
130
131
	/**
132
	 * @param IOutput $output
133
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
134
	 * @param array $options
135
	 */
136
	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) {
137
	}
138
}
139