Version0820Date20210708130230   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 28
ccs 0
cts 12
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureColumnIsNullable() 0 10 2
A changeSchema() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace OCA\FaceRecognition\Migration;
6
7
use Closure;
8
use OCP\DB\ISchemaWrapper;
9
use OCP\Migration\IOutput;
10
use OCP\Migration\SimpleMigrationStep;
11
12
/**
13
 * Auto-generated migration step: Please modify to your needs!
14
 */
15
class Version0820Date20210708130230 extends SimpleMigrationStep {
16
17
	/**
18
	 * @param IOutput $output
19
	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
20
	 * @param array $options
21
	 * @return null|ISchemaWrapper
22
	 */
23
	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
24
		/** @var ISchemaWrapper $schema */
25
		$schema = $schemaClosure();
26
27
		$this->ensureColumnIsNullable($schema, 'facerecog_persons', 'is_valid');
28
		$this->ensureColumnIsNullable($schema, 'facerecog_images', 'is_processed');
29
30
		return null;
31
	}
32
33
	protected function ensureColumnIsNullable(ISchemaWrapper $schema, string $tableName, string $columnName): bool {
34
		$table = $schema->getTable($tableName);
35
		$column = $table->getColumn($columnName);
36
37
		if ($column->getNotnull()) {
38
			$column->setNotnull(false);
39
			return true;
40
		}
41
42
		return false;
43
	}
44
45
}
46