Completed
Push — master ( dd406c...9f6102 )
by Mahmoud
03:15
created

CreateUserBySocialProfileTask::run()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 37
Code Lines 29

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
rs 8.8571
cc 2
eloc 29
nc 2
nop 11

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace App\Containers\SocialAuthentication\Tasks;
4
5
use App\Containers\Authentication\Tasks\ApiAuthenticationTask;
6
use App\Containers\User\Contracts\UserRepositoryInterface;
7
use App\Containers\User\Exceptions\AccountFailedException;
8
use App\Port\Task\Abstracts\Task;
9
use Exception;
10
11
/**
12
 * Class CreateUserBySocialProfileTask.
13
 *
14
 * @author Mahmoud Zalt <[email protected]>
15
 */
16
class CreateUserBySocialProfileTask extends Task
17
{
18
19
    /**
20
     * @var \App\Containers\User\Contracts\UserRepositoryInterface
21
     */
22
    private $userRepository;
23
24
    /**
25
     * CreateUserByVisitorIdTask constructor.
26
     *
27
     * @param \App\Containers\User\Contracts\UserRepositoryInterface $userRepository
28
     */
29
    public function __construct(UserRepositoryInterface $userRepository)
30
    {
31
        $this->userRepository = $userRepository;
32
    }
33
34
35
    /**
36
     * @param      $provider
37
     * @param null $token
38
     * @param null $socialId
39
     * @param null $nickname
40
     * @param null $name
41
     * @param null $email
42
     * @param null $avatar
43
     * @param null $tokenSecret
44
     * @param null $expiresIn
45
     * @param null $refreshToken
46
     * @param null $avatar_original
47
     *
48
     * @return  mixed
49
     */
50
    public function run(
51
        $provider,
52
        $token = null,
53
        $socialId = null,
54
        $nickname = null,
55
        $name = null,
56
        $email = null,
57
        $avatar = null,
58
        $tokenSecret = null,
59
        $expiresIn = null,
60
        $refreshToken = null,
61
        $avatar_original = null
62
    ) {
63
64
        $data = [
65
            'social_provider'        => $provider,
66
            'social_token'           => $token,
67
            'social_refresh_token'   => $refreshToken,
68
            'social_token_secret'    => $tokenSecret,
69
            'social_expires_in'      => $expiresIn,
70
            'social_id'              => $socialId,
71
            'social_nickname'        => $nickname,
72
            'social_avatar'          => $avatar,
73
            'social_avatar_original' => $avatar_original,
74
            'email'                  => $email,
75
            'name'                   => $name,
76
        ];
77
78
        try {
79
            // create new user
80
            $user = $this->userRepository->create($data);
81
        } catch (Exception $e) {
82
            throw (new AccountFailedException())->debug($e);
83
        }
84
85
        return $user;
86
    }
87
88
89
}
90