Completed
Push — master ( d62417...7b2aa5 )
by René
10:14 queued 11s
created

Version0010Date20191221183157::changeSchema()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 80
Code Lines 56

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 56
nc 4
nop 3
dl 0
loc 80
ccs 0
cts 75
cp 0
crap 12
rs 8.9599
c 1
b 0
f 0

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
 * @copyright Copyright (c) 2017 René Gieling <[email protected]>
4
 *
5
 * @author René Gieling <[email protected]>
6
 *
7
 * @license GNU AGPL version 3 or any later version
8
 *
9
 *  This program is free software: you can redistribute it and/or modify
10
 *  it under the terms of the GNU Affero General Public License as
11
 *  published by the Free Software Foundation, either version 3 of the
12
 *  License, or (at your option) any later version.
13
 *
14
 *  This program is distributed in the hope that it will be useful,
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 *  GNU Affero General Public License for more details.
18
 *
19
 *  You should have received a copy of the GNU Affero General Public License
20
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
21
 *
22
 */
23
24
namespace OCA\Polls\Migration;
25
26
// use Doctrine\DBAL\Exception\TableNotFoundException;
27
// use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
28
use Doctrine\DBAL\Types\Type;
0 ignored issues
show
Bug introduced by
The type Doctrine\DBAL\Types\Type was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
29
use OCP\DB\ISchemaWrapper;
30
use OCP\DB\QueryBuilder\IQueryBuilder;
31
use OCP\IConfig;
32
use OCP\IDBConnection;
33
use OCP\Migration\SimpleMigrationStep;
34
use OCP\Migration\IOutput;
35
use OCP\Security\ISecureRandom;
36
37
/**
38
 * Installation class for the polls app.
39
 * Initial db creation
40
 */
41
class Version0010Date20191221183157 extends SimpleMigrationStep {
42
43
	/** @var IDBConnection */
44
	protected $connection;
45
46
	/** @var IConfig */
47
	protected $config;
48
49
	/**
50
	 * @param IDBConnection $connection
51
	 * @param IConfig $config
52
	 */
53
	public function __construct(IDBConnection $connection, IConfig $config) {
54
		$this->connection = $connection;
55
		$this->config = $config;
56
	}
57
58
	/**
59
	 * @param IOutput $output
60
	 * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
61
	 * @param array $options
62
	 * @return null|ISchemaWrapper
63
	 * @since 13.0.0
64
	 */
65
	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
66
		/** @var ISchemaWrapper $schema */
67
		$schema = $schemaClosure();
68
69
		if (!$schema->hasTable('polls_notice')) {
70
			$table = $schema->createTable('polls_notice');
71
			$table->addColumn('id', Type::INTEGER, [
72
				'autoincrement' => true,
73
				'notnull' => true,
74
			]);
75
			$table->addColumn('poll_id', Type::INTEGER, [
76
				'notnull' => true
77
			]);
78
			$table->addColumn('channel', Type::STRING, [
79
				'notnull' => false,
80
				'length' => 64
81
			]);
82
			$table->addColumn('user_id', Type::STRING, [
83
				'notnull' => false,
84
				'length' => 1024
85
			]);
86
			$table->addColumn('user_email', Type::STRING, [
87
				'notnull' => false,
88
				'length' => 1024
89
			]);
90
			$table->addColumn('display_name', Type::STRING, [
91
				'notnull' => false,
92
				'length' => 64
93
			]);
94
			$table->addColumn('message_id', Type::STRING, [
95
				'notnull' => false,
96
				'length' => 64
97
			]);
98
			$table->addColumn('message', Type::STRING, [
99
				'notnull' => false,
100
				'length' => 1024
101
			]);
102
103
			$table->setPrimaryKey(['id']);
104
		}
105
106
		if (!$schema->hasTable('polls_log')) {
107
			$table = $schema->createTable('polls_log');
108
			$table->addColumn('id', Type::INTEGER, [
109
				'autoincrement' => true,
110
				'notnull' => true
111
			]);
112
			$table->addColumn('created', Type::INTEGER, [
113
				'notnull' => true,
114
				'length' => 11,
115
				'default' => 0
116
			]);
117
			$table->addColumn('processed', Type::INTEGER, [
118
				'notnull' => true,
119
				'length' => 11,
120
				'default' => 0
121
			]);
122
			$table->addColumn('poll_id', Type::INTEGER, [
123
				'notnull' => true
124
			]);
125
			$table->addColumn('user_id', Type::STRING, [
126
				'notnull' => false,
127
				'length' => 1024
128
			]);
129
			$table->addColumn('display_name', Type::STRING, [
130
				'notnull' => false,
131
				'length' => 64
132
			]);
133
			$table->addColumn('message_id', Type::STRING, [
134
				'notnull' => false,
135
				'length' => 64
136
			]);
137
			$table->addColumn('message', Type::STRING, [
138
				'notnull' => false,
139
				'length' => 1024
140
			]);
141
			$table->setPrimaryKey(['id']);
142
		}
143
144
		return $schema;
145
	}
146
147
}
148