ReorderUserFields::down()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 28
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 21
c 1
b 1
f 0
nc 1
nop 0
dl 0
loc 28
rs 9.584
1
<?php
2
3
use Uccello\Core\Database\Migrations\Migration;
4
use Uccello\Core\Models\Module;
5
use Uccello\Core\Models\Field;
6
7
class ReorderUserFields extends Migration
8
{
9
    /**
10
     * Run the migrations.
11
     *
12
     * @return void
13
     */
14
    public function up()
15
    {
16
        $userModule = Module::where('name', 'user')->first();
17
18
        $emailField = Field::where('module_id', $userModule->id)
19
            ->where('name', 'email')
20
            ->first();
21
        $emailField->sequence = 3;
0 ignored issues
show
Bug introduced by
The property sequence does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
22
        $emailField->save();
23
24
        $passwordField = Field::where('module_id', $userModule->id)
25
            ->where('name', 'password')
26
            ->first();
27
        $passwordField->sequence = 4;
28
        $passwordField->save();
29
30
        $nameField = Field::where('module_id', $userModule->id)
31
            ->where('name', 'name')
32
            ->first();
33
        $nameField->data = [ 'rules' => 'required', 'icon' => 'person' ];
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
34
        $nameField->save();
35
36
        $usernameField = Field::where('module_id', $userModule->id)
37
            ->where('name', 'username')
38
            ->first();
39
        $usernameField->data = [ 'rules' => 'required|regex:/^[a-zA-Z0-9.-_]+$/|unique:users,username,%id%', 'icon' => 'vpn_key' ];
40
        $usernameField->save();
41
42
    }
43
44
    /**
45
     * Reverse the migrations.
46
     *
47
     * @return void
48
     */
49
    public function down()
50
    {
51
        $userModule = Module::where('name', 'user')->first();
52
53
        $emailField = Field::where('module_id', $userModule->id)
54
            ->where('name', 'email')
55
            ->first();
56
        $emailField->sequence = 4;
0 ignored issues
show
Bug introduced by
The property sequence does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
57
        $emailField->save();
58
59
60
        $passwordField = Field::where('module_id', $userModule->id)
61
            ->where('name', 'password')
62
            ->first();
63
        $passwordField->sequence = 3;
64
        $passwordField->save();
65
66
        $nameField = Field::where('module_id', $userModule->id)
67
            ->where('name', 'name')
68
            ->first();
69
        $nameField->data = null;
0 ignored issues
show
Bug introduced by
The property data does not seem to exist on Uccello\Core\Models\Field. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
        $nameField->save();
71
72
        $usernameField = Field::where('module_id', $userModule->id)
73
            ->where('name', 'username')
74
            ->first();
75
        $usernameField->data = [ 'rules' => 'required|regex:/^[a-zA-Z0-9.-_]+$/|unique:users,username,%id%', 'icon' => 'person' ];
76
        $usernameField->save();
77
    }
78
}
79