Completed
Push — master ( 564b36...cbd880 )
by Julius
01:11 queued 01:11
created

Version30709Date20201111104147::changeSchema()   F

Complexity

Conditions 11
Paths 1024

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 20
rs 3.15
c 0
b 0
f 0
cc 11
nc 1024
nop 3

How to fix   Complexity   

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\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
class Version30709Date20201111104147 extends SimpleMigrationStep {
13
14
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
15
		/** @var ISchemaWrapper $schema */
16
		$schema = $schemaClosure();
17
18
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'version');
19
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'canwrite') || $result;
20
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'token') || $result;
21
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'hide_download') || $result;
22
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'direct') || $result;
23
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'is_remote_token') || $result;
24
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'remote_server') || $result;
25
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_wopi', 'remote_server_token') || $result;
26
27
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_direct', 'timestamp') || $result;
28
		$result = $this->ensureColumnIsNullable($schema, 'richdocuments_assets', 'timestamp') || $result;
29
30
31
32
		return $result ? $schema : null;
33
	}
34
35
	protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
36
		$table = $schema->getTable($tableName);
37
		$column = $table->getColumn($columnName);
38
39
		if ($column->getNotnull()) {
40
			$column->setNotnull(false);
41
			return true;
42
		}
43
44
		return false;
45
	}
46
}
47