Completed
Push — master ( 739835...9cb3a5 )
by Mahmoud
03:59
created

UpdateVisitorUserAction   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
A run() 0 17 3
1
<?php
2
3
namespace App\Containers\User\Actions;
4
5
use App\Containers\Authentication\Exceptions\MissingVisitorIdException;
6
use App\Containers\Authentication\Tasks\ApiLoginThisUserObjectTask;
7
use App\Containers\User\Tasks\FindUserByVisitorIdTask;
8
use App\Containers\User\Tasks\UpdateUserTask;
9
use App\Port\Action\Abstracts\Action;
10
11
/**
12
 * Class UpdateVisitorUserAction.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class UpdateVisitorUserAction extends Action
17
{
18
19
    /**
20
     * @var  \App\Containers\User\Tasks\FindUserByVisitorIdTask
21
     */
22
    private $findUserByVisitorIdTask;
23
24
    /**
25
     * @var  \App\Containers\User\Tasks\UpdateUserTask
26
     */
27
    private $updateUserTask;
28
29
    /**
30
     * @var  \App\Containers\User\Actions\ApiLoginThisUserObjectTask
31
     */
32
    private $apiLoginThisUserObjectTask;
33
34
    /**
35
     * UpdateVisitorUserAction constructor.
36
     *
37
     * @param \App\Containers\User\Tasks\FindUserByVisitorIdTask      $findUserByVisitorIdTask
38
     * @param \App\Containers\User\Tasks\UpdateUserTask               $updateUserTask
39
     * @param \App\Containers\User\Actions\ApiLoginThisUserObjectTask $apiLoginThisUserObjectTask
40
     */
41
    public function __construct(
42
        FindUserByVisitorIdTask $findUserByVisitorIdTask,
43
        UpdateUserTask $updateUserTask,
44
        ApiLoginThisUserObjectTask $apiLoginThisUserObjectTask
45
    ) {
46
        $this->findUserByVisitorIdTask = $findUserByVisitorIdTask;
47
        $this->updateUserTask = $updateUserTask;
48
        $this->apiLoginThisUserObjectTask = $apiLoginThisUserObjectTask;
0 ignored issues
show
Documentation Bug introduced by
It seems like $apiLoginThisUserObjectTask of type object<App\Containers\Au...oginThisUserObjectTask> is incompatible with the declared type object<App\Containers\Us...oginThisUserObjectTask> of property $apiLoginThisUserObjectTask.

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...
49
    }
50
51
    /**
52
     * This will register an existing User Visitor. After being created by the middleware.
53
     * Only case the "Registration by Device ID" feature is enabled, via its middleware.
54
     *
55
     * @param      $visitorId
56
     * @param null $email
57
     * @param null $password
58
     * @param null $name
59
     *
60
     * @return  mixed
61
     */
62
    public function run($visitorId, $email = null, $password = null, $name = null, $gender = null, $birth = null)
63
    {
64
        if (!$visitorId) {
65
            throw (new MissingVisitorIdException())->debug('from (UpdateVisitorUserAction)');
66
        }
67
68
        $user = $this->findUserByVisitorIdTask->run($visitorId);
69
70
        if ($user) {
71
            // update the existing user by adding his credentials
72
            $user = $this->updateUserTask->run($user->id, $password, $name, $email, $gender, $birth);
73
            // Login the User from his object
74
            $user = $this->apiLoginThisUserObjectTask->run($user);
75
        }
76
77
        return $user;
78
    }
79
}
80