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

RemoveLegacyPasswordHashes::up()   B

Complexity

Conditions 5
Paths 9

Size

Total Lines 24
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 11
nc 9
nop 0
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
1
<?php
2
3
use Phinx\Migration\AbstractMigration;
4
5
class RemoveLegacyPasswordHashes extends AbstractMigration
6
{
7
    /**
8
     * Remove legacy password hashes
9
     */
10
    public function up() {
11
12
    	if (!$this->hasTable('users_entity')) {
13
    		return;
14
		}
15
16
		// remove legacy 2.x password and salt columns
17
		$table = $this->table('users_entity');
18
19
		if ($table->hasIndex('password')) {
20
			$table->removeIndexByName('password');
21
		}
22
23
		if ($table->hasColumn('password')) {
24
			$table->removeColumn('password');
25
		}
26
27
		if ($table->hasColumn('salt')) {
28
			$table->removeColumn('salt');
29
		}
30
		
31
		$table->save();
32
33
    }
34
35
    public function down() {
36
37
		if (!$this->hasTable('users_entity')) {
38
			return;
39
		}
40
41
		$table = $this->table('users_entity');
42
		
43 View Code Duplication
		if (!$table->hasColumn('password')) {
1 ignored issue
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...
44
			$table->addColumn('password', 'text', [
45
				'null' => false,
46
				'default' => '',
47
				'limit' => 32,
48
			]);
49
		}
50
51 View Code Duplication
		if (!$table->hasColumn('salt')) {
1 ignored issue
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...
52
			$table->addColumn('salt', 'text', [
53
				'null' => false,
54
				'default' => '',
55
				'limit' => 8,
56
			]);
57
		}
58
59
		if (!$table->hasIndex('password')) {
60
			$table->addIndex(['password'], [
61
				'name' => 'password',
62
				'unique' => false,
63
			]);
64
		}
65
66
		$table->save();
67
68
	}
69
}
70