ProblemMigration::transform()   A
last analyzed

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
c 1
b 0
f 0
nc 8
nop 1
dl 0
loc 20
rs 9.8333
1
<?php
2
3
namespace App\Console\Commands\Migrations;
4
5
use App\Entities\Problem;
6
7
class ProblemMigration extends Migration
8
{
9
    public function handle($command)
10
    {
11
        $command->info('Migrating Problems...');
12
        $this->table('problem')->orderBy('problem_id', 'asc')->chunk(100, function ($objects) {
13
            $objects->map(function ($object) {
14
                $this->transform($object);
15
            });
16
        });
17
        $command->info('Migrating Problems Done');
18
    }
19
20
    private function transform($object)
21
    {
22
        $problem = new Problem();
23
        $problem->fill(get_object_vars($object));
24
        $problem->id = $object->problem_id;
25
        $problem->title = $object->title;
26
        $problem->description = $object->description;
27
        $problem->created_at = $object->in_date;
28
29
        if ($problem->submit === null) {
30
            $problem->submit = 0;
31
        }
32
        if ($problem->accepted === null) {
33
            $problem->accepted = 0;
34
        }
35
        if ($object->defunct === 'Y') {
36
            $problem->status = Problem::ST_HIDE;
37
        }
38
39
        $problem->save();
40
    }
41
}
42