Completed
Push — master ( 012634...6d13cc )
by Mahmoud
03:45
created

CreateUserWithCredentialsAction   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A run() 0 9 1
1
<?php
2
3
namespace App\Containers\User\Actions;
4
5
use App\Containers\User\Events\Events\UserCreatedEvent;
6
use App\Containers\User\Services\CreateUserService;
7
use App\Port\Action\Abstracts\Action;
8
use App\Port\Event\Dispatcher\EventsDispatcher;
9
10
/**
11
 * Class CreateUserWithCredentialsAction.
12
 *
13
 * @author Mahmoud Zalt <[email protected]>
14
 */
15
class CreateUserWithCredentialsAction extends Action
16
{
17
18
    /**
19
     * @var  \App\Containers\User\Actions\CreateUserService
20
     */
21
    private $createUserService;
22
23
    /**
24
     * @var  \App\Port\Event\Dispatcher\EventsDispatcher
25
     */
26
    private $eventsDispatcher;
27
28
    /**
29
     * CreateUserWithCredentialsAction constructor.
30
     *
31
     * @param \App\Containers\User\Services\CreateUserService $createUserService
32
     * @param \App\Port\Event\Dispatcher\EventsDispatcher     $eventsDispatcher
33
     */
34
    public function __construct(CreateUserService $createUserService, EventsDispatcher $eventsDispatcher)
35
    {
36
        $this->createUserService = $createUserService;
0 ignored issues
show
Documentation Bug introduced by
It seems like $createUserService of type object<App\Containers\Us...ices\CreateUserService> is incompatible with the declared type object<App\Containers\Us...ions\CreateUserService> of property $createUserService.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
37
        $this->eventsDispatcher = $eventsDispatcher;
38
    }
39
40
    /**
41
     * create a new user object.
42
     * optionally can login the created user and return it with its token.
43
     *
44
     * @param      $email
45
     * @param      $password
46
     * @param      $name
47
     * @param bool $login determine weather to login or not after creating
48
     *
49
     * @return mixed
50
     */
51
    public function run($email, $password, $name, $login = false)
52
    {
53
        $user = $this->createUserService->byCredentials($email, $password, $name, $login);
54
55
        // Fire a User Created Event
56
        $this->eventsDispatcher->fire(New UserCreatedEvent($user));
57
58
        return $user;
59
    }
60
}
61