Completed
Push — master ( 58043b...413e7c )
by Sergi Tur
06:39
created

PersistUserMigrationInDatabase::handle()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
nc 3
nop 1
dl 0
loc 15
rs 9.4285
c 1
b 0
f 0
1
<?php
2
3
namespace Acacha\Users\Listeners;
4
5
use Acacha\Users\Events\UserHasBeenMigrated;
6
use Acacha\Users\Events\UserMigrationHasBeenPersisted;
7
use Acacha\Users\Models\UserMigration;
8
9
/**
10
 * Class PersistUserMigrationInDatabase.
11
 *
12
 */
13
class PersistUserMigrationInDatabase
14
{
15
    /**
16
     * PersistUserMigrationInDatabase constructor.
17
     */
18
    public function __construct()
19
    {
20
        //
21
    }
22
23
    /**
24
     * Handle the event.
25
     *
26
     * @param  UserHasBeenMigrated  $event
27
     * @return void
28
     */
29
    public function handle(UserHasBeenMigrated $event)
30
    {
31
        try {
32
            $newUserMigration = UserMigration::create([
0 ignored issues
show
Bug introduced by
The method create() does not exist on Acacha\Users\Models\UserMigration. Did you maybe mean created()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
33
                'source_user_id' => $event->sourceUserId,
34
                'source_user' => $event->sourceUser,
35
                'user_id' => $event->newUser ? $event->newUser->id : null,
36
                'user_migration_batch_id' => $event->user_migration_batch_id
37
            ]);
38
            event(new UserMigrationHasBeenPersisted($newUserMigration));
39
        } catch (\Exception $e) {
40
            dump($e->getMessage());
41
        }
42
43
    }
44
45
}