Passed
Push — master ( 3c693d...ccd5ca )
by Roeland
28:56 queued 14:09
created

Version21000Date20201120141228::changeSchema()   B

Complexity

Conditions 9
Paths 108

Size

Total Lines 51
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
cc 9
eloc 30
c 5
b 0
f 0
nc 108
nop 3
dl 0
loc 51
rs 7.9888

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 OC\Core\Migrations;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
class Version21000Date20201120141228 extends SimpleMigrationStep {
13
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
14
		/** @var ISchemaWrapper $schema */
15
		$schema = $schemaClosure();
16
17
		if ($schema->hasTable('authtoken')) {
18
			$table = $schema->getTable('authtoken');
19
			$loginNameColumn = $table->getColumn('login_name');
20
			if ($loginNameColumn->getLength() !== 255) {
21
				$loginNameColumn->setLength(255);
22
			}
23
			$table->changeColumn('type', [
24
				'notnull' => false,
25
			]);
26
			$table->changeColumn('remember', [
27
				'notnull' => false,
28
			]);
29
			$table->changeColumn('last_activity', [
30
				'notnull' => false,
31
			]);
32
			$table->changeColumn('last_check', [
33
				'notnull' => false,
34
			]);
35
		}
36
37
		if ($schema->hasTable('dav_job_status')) {
38
			$schema->dropTable('dav_job_status');
39
		}
40
41
		if ($schema->hasTable('systemtag')) {
42
			$table = $schema->getTable('systemtag');
43
			if ($table->hasColumn('systemtag')) {
44
				$table->dropColumn('assignable');
45
			}
46
		}
47
48
		if ($schema->hasTable('share')) {
49
			$table = $schema->getTable('share');
50
			if ($table->hasColumn('attributes')) {
51
				$table->dropColumn('attributes');
52
			}
53
		}
54
55
		if ($schema->hasTable('jobs')) {
56
			$table = $schema->getTable('jobs');
57
			$table->changeColumn('execution_duration', [
58
				'notnull' => false,
59
				'default' => 0,
60
			]);
61
		}
62
63
		return $schema;
64
	}
65
}
66