RoutineOrganizerCreateJob   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 45
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A handle() 0 21 2
1
<?php
2
3
namespace Gamer\Jobs;
4
5
use Illuminate\Bus\Queueable;
6
use Illuminate\Queue\SerializesModels;
7
use Illuminate\Queue\InteractsWithQueue;
8
use Illuminate\Contracts\Queue\ShouldQueue;
9
use Illuminate\Foundation\Bus\Dispatchable;
10
11
use App\Models\User;
12
use Gamer\Models\Role;
13
use Gamer\Services\PaymentGatewayService;
14
use Log;
15
use Gamer\Tools\Organizer;
16
17
class RoutineOrganizerCreateJob implements ShouldQueue
18
{
19
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
20
21
    protected $user;
22
    protected $companyToken;
23
24
    /**
25
     * Create a new job instance.
26
     *
27
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
28
     */
29
    public function __construct(User $user, $companyToken)
30
    {
31
        $this->user = $user;
32
        $this->companyToken = $companyToken;
33
    }
34
35
    /**
36
     * Execute the job.
37
     *
38
     * @return void
39
     */
40
    public function handle()
41
    {
42
        $organizerResult = Organizer::getOrganizerServiceForUser($this->user, $this->companyToken)->foundOrganizerDataByToken();
43
        if (empty($organizerResult)) {
44
            return false;
45
        }
46
47
        DB::table('users')->firstOrCreate(
48
            [
49
            'name'              => $organizerResult['name'],
50
            'cpf'               => $organizerResult['cpf'],
51
            'email'             => $organizerResult['email'],
52
            'password'          => bcrypt('q1w2e3r4'.rand()),
53
            'token'             => \SiUtils\Helper\General::generateToken(),
54
            'token_public'      => $this->companyToken,
55
            'role_id'           => Role::$CLIENT
56
            ]
57
        );
58
59
        return true;
60
    }
61
}
62