UserMigration::handle()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 9
rs 10
1
<?php
2
3
namespace App\Console\Commands\Migrations;
4
5
use App\Entities\User;
6
7
class UserMigration extends Migration
8
{
9
    public function handle($command)
10
    {
11
        $command->info('Migrating Users...');
12
        $this->table('users')->orderBy('reg_time', 'asc')->chunk(100, function ($objects) {
13
            foreach ($objects as $object) {
14
                $this->transform($object);
15
            }
16
        });
17
        $command->info('Migrating Users Done');
18
    }
19
20
    private function transform($object)
21
    {
22
        $user = new User();
23
        $user->fill(get_object_vars($object));
24
        $user->username = $object->user_id;
25
        $user->created_at = $object->reg_time;
26
        $user->updated_at = $object->reg_time;
27
        $user->password = $object->password;
28
        $user->status = User::ST_ACTIVE;
29
        if ($object->defunct === 'Y') {
30
            $user->status = User::ST_INACTIVE;
31
        }
32
        $user->save();
33
    }
34
}
35