Completed
Push — reformat ( 7da2f3 )
by Victor
05:31
created

Version20170808220321::changeSchema()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 102
Code Lines 64

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 102
rs 8.2857
c 0
b 0
f 0
cc 3
eloc 64
nc 4
nop 2

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