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

PersistUserMigrationInDatabase   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 4
lcom 0
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A handle() 0 15 3
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
}