Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
UpdateCustomerLastConnection
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
2 / 2
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 handle
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace App\Jobs;
4
5use App\Models\Customer;
6use App\Models\CustomerLogin;
7use Illuminate\Bus\Queueable;
8use Illuminate\Contracts\Queue\ShouldQueue;
9use Illuminate\Foundation\Bus\Dispatchable;
10use Illuminate\Queue\InteractsWithQueue;
11use Illuminate\Queue\SerializesModels;
12use Illuminate\Support\Carbon;
13
14class UpdateCustomerLastConnection implements ShouldQueue
15{
16    use Dispatchable;
17    use InteractsWithQueue;
18    use Queueable;
19    use SerializesModels;
20
21    /** @var \Illuminate\Support\Carbon */
22    protected $date = null;
23
24    /** @var \App\Models\Customer */
25    protected $customer = null;
26
27    /** @var \App\Models\CustomerLogin */
28    protected $customerLogin = null;
29
30    /**
31     * Create a new job instance.
32     *
33     * @param \App\Models\Customer       $customer
34     * @param \App\Models\CustomerLogin  $customerLogin
35     * @param \Illuminate\Support\Carbon $date
36     * @return void
37     */
38    public function __construct(
39        Customer $customer,
40        CustomerLogin $customerLogin,
41        Carbon $date
42    ) {
43        $this->date          = $date;
44        $this->customer      = $customer;
45        $this->customerLogin = $customerLogin;
46    }
47
48    /**
49     * Execute the job.
50     *
51     * @return void
52     */
53    public function handle(): void
54    {
55        if ($this->customerLogin->last_connection < $this->date) {
56            $this->customerLogin->last_connection = $this->date;
57            $this->customer->logins()->save($this->customerLogin);
58        }
59    }
60}