Completed
Push — master ( 86f141...44405f )
by Julius
09:32 queued 08:03
created

Version30704Date20200626072306::changeSchema()   B

Complexity

Conditions 8
Paths 128

Size

Total Lines 58

Duplication

Lines 18
Ratio 31.03 %

Code Coverage

Tests 0
CRAP Score 72

Importance

Changes 0
Metric Value
dl 18
loc 58
ccs 0
cts 48
cp 0
rs 7.4852
c 0
b 0
f 0
cc 8
nc 128
nop 3
crap 72

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
namespace OCA\Richdocuments\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\SimpleMigrationStep;
10
use OCP\Migration\IOutput;
11
12
class Version30704Date20200626072306 extends SimpleMigrationStep {
13
14
	/**
15
	 * @param IOutput $output
16
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
17
	 * @param array $options
18
	 * @return null|ISchemaWrapper
19
	 */
20
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
21
		/** @var ISchemaWrapper $schema */
22
		$schema = $schemaClosure();
23
24
		$table = $schema->getTable('richdocuments_wopi');
25
26
		if (!$table->hasColumn('template_id')) {
27
			$table->addColumn('template_id', 'integer', [
28
				'notnull' => false,
29
				'length' => 4,
30
			]);
31
		}
32
33 View Code Duplication
		if (!$table->hasColumn('hide_download')) {
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...
34
			$table->addColumn('hide_download', 'boolean', [
35
				'notnull' => true,
36
				'default' => false,
37
			]);
38
		}
39
40
		if (!$table->hasColumn('share')) {
41
			$table->addColumn('share', 'string', [
42
				'notnull' => false,
43
				'length' => 64
44
			]);
45
		}
46
47 View Code Duplication
		if (!$table->hasColumn('direct')) {
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...
48
			$table->addColumn('direct', 'boolean', [
49
				'notnull' => true,
50
				'default' => false,
51
			]);
52
		}
53 View Code Duplication
		if (!$table->hasColumn('is_remote_token')) {
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...
54
			$table->addColumn('is_remote_token', 'boolean', [
55
				'notnull' => true,
56
				'default' => false,
57
			]);
58
		}
59
60
		if (!$table->hasColumn('remote_server')) {
61
			$table->addColumn('remote_server', 'string', [
62
				'notnull' => true,
63
				'default' => '',
64
			]);
65
66
		}
67
		if (!$table->hasColumn('remote_server_token')) {
68
			$table->addColumn('remote_server_token', 'string', [
69
				'notnull' => true,
70
				'length' => 32,
71
				'default' => '',
72
			]);
73
		}
74
75
76
		return $schema;
77
	}
78
}
79