ArticleMigration   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 23
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 9 1
A transformArticle() 0 10 1
1
<?php
2
3
namespace App\Console\Commands\Migrations;
4
5
use App\Entities\Post;
6
use App\Services\UserService;
7
8
class ArticleMigration extends Migration
9
{
10
    public function handle($command)
11
    {
12
        $command->info('Migrating Articles...');
13
        $this->table('news')->orderBy('news_id', 'asc')->chunk(100, function ($objects) {
14
            $objects->map(function ($object) {
15
                $this->transformArticle($object);
16
            });
17
        });
18
        $command->info('Migrating Articles Done');
19
    }
20
21
    private function transformArticle($object)
22
    {
23
        $post = new Post();
24
        $post->title = $object->title;
25
        $post->content = $object->content;
26
        $author = app(UserService::class)->findByName($object->user_id);
27
        $post->user_id = $author->id;
28
        $post->created_at = $object->time;
29
        $post->priority = $object->importance;
30
        $post->save();
31
    }
32
}
33