UserMigration   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 16
c 2
b 0
f 0
dl 0
loc 26
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 13 2
A handle() 0 9 2
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