Version20170808220321::changeSchema()   B
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 102

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 102
ccs 0
cts 94
cp 0
rs 8
c 0
b 0
f 0
cc 3
nc 4
nop 2
crap 12

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
 * Files_antivirus
4
 *
5
 * This file is licensed under the Affero General Public License version 3 or
6
 * later. See the COPYING file.
7
 *
8
 * @author Viktar Dubiniuk <[email protected]>
9
 *
10
 * @copyright Viktar Dubiniuk 2018
11
 * @license AGPL-3.0
12
 */
13
14
namespace OCA\Files_Antivirus\Migrations;
15
use Doctrine\DBAL\Schema\Schema;
16
use OCP\Migration\ISchemaMigration;
17
18
/**
19
 * Creates initial schema
20
 */
21
class Version20170808220321 implements ISchemaMigration {
22
	/**
23
	 * @param Schema $schema
24
	 * @param array $options
25
	 *
26
	 * @return void
27
	 */
28
	public function changeSchema(Schema $schema, array $options) {
29
		$prefix = $options['tablePrefix'];
30
		if (!$schema->hasTable("{$prefix}files_antivirus")) {
31
			$table = $schema->createTable("{$prefix}files_antivirus");
32
			$table->addColumn(
33
				'fileid',
34
				'bigint',
35
				[
36
					'unsigned' => true,
37
					'notnull' => true,
38
					'length' => 11,
39
				]
40
			);
41
42
			$table->addColumn(
43
				'check_time',
44
				'integer',
45
				[
46
					'notnull' => true,
47
					'unsigned' => true,
48
					'default' => 0,
49
				]
50
			);
51
			$table->setPrimaryKey(['fileid']);
52
		}
53
54
		if (!$schema->hasTable("{$prefix}files_avir_status")) {
55
			$table = $schema->createTable("{$prefix}files_avir_status");
56
			$table->addColumn(
57
				'id',
58
				'integer',
59
				[
60
					'autoincrement' => true,
61
					'unsigned' => true,
62
					'notnull' => true,
63
					'length' => 11,
64
				]
65
			);
66
67
			$table->addColumn(
68
				'group_id',
69
				'integer',
70
				[
71
					'notnull' => true,
72
					'unsigned' => true,
73
					'default' => 0,
74
				]
75
			);
76
77
			$table->addColumn(
78
				'status_type',
79
				'integer',
80
				[
81
					'notnull' => true,
82
					'unsigned' => true,
83
					'default' => 0,
84
				]
85
			);
86
87
			$table->addColumn(
88
				'result',
89
				'integer',
90
				[
91
					'notnull' => true,
92
					'unsigned' => false,
93
					'default' => 0,
94
				]
95
			);
96
97
			$table->addColumn(
98
				'match',
99
				'string',
100
				[
101
					'length' => 64,
102
					'notnull' => false,
103
					'default' => null,
104
				]
105
			);
106
107
			$table->addColumn(
108
				'description',
109
				'string',
110
				[
111
					'length' => 64,
112
					'notnull' => false,
113
					'default' => null,
114
				]
115
			);
116
117
			$table->addColumn(
118
				'status',
119
				'integer',
120
				[
121
					'length' => 4,
122
					'notnull' => true,
123
					'default' => 0,
124
					'unsigned' => false,
125
				]
126
			);
127
			$table->setPrimaryKey(['id']);
128
		}
129
	}
130
}
131