Test Failed
Push — master ( fe71c4...38b5f5 )
by Jeroen
02:19
created

ExpandTextColumnsToLongtext::up()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 20
Code Lines 10

Duplication

Lines 20
Ratio 100 %

Importance

Changes 0
Metric Value
cc 5
eloc 10
nc 5
nop 0
dl 20
loc 20
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
use Phinx\Db\Adapter\MysqlAdapter;
4
use Phinx\Migration\AbstractMigration;
5
6
class ExpandTextColumnsToLongtext extends AbstractMigration {
7
8
	// Columns that change from text to longtext
9
	private $text_to_longtext = [
10
		'annotations' => ['value'],
11
		'config' => ['value'],
12
		'groups_entity' => ['description'],
13
		'metadata' => ['value'],
14
		'objects_entity' => ['description'],
15
		'private_settings' => ['value'],
16
		'sites_entity' => ['description'],
17
	];
18
19
	/**
20
	 * Expand certain columns from text to longtext
21
	 */
22 View Code Duplication
	public function up() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
23
24
		foreach ($this->text_to_longtext as $table => $columns) {
25
			if (!$this->hasTable($table)) {
26
				continue;
27
			}
28
29
			$table = $this->table($table);
30
31
			foreach ($columns as $column) {
32
				if ($table->hasColumn($column)) {
33
					$table->changeColumn($column, 'text', [
34
						'limit' => MysqlAdapter::TEXT_LONG,
35
					]);
36
				}
37
			}
38
39
			$table->save();
40
		}
41
	}
42
43
	/**
44
	 * Shirnk certain columns from longtext to text
45
	 */
46 View Code Duplication
	public function down() {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
47
48
		foreach ($this->text_to_longtext as $table => $columns) {
49
			if (!$this->hasTable($table)) {
50
				continue;
51
			}
52
53
			$table = $this->table($table);
54
55
			foreach ($columns as $column) {
56
				if ($table->hasColumn($column)) {
57
					$table->changeColumn($column, 'text', [
58
						'limit' => MysqlAdapter::TEXT_REGULAR,
59
					]);
60
				}
61
			}
62
63
			$table->save();
64
		}
65
	}
66
}
67