Passed
Push — master ( ef93dc...4f7931 )
by
unknown
13:58
created

DbLogger::handle()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
ccs 11
cts 11
cp 1
cc 2
nc 2
nop 0
crap 2
1
<?php
2
3
/*
4
 * This file is part of ibrand/laravel-sms.
5
 *
6
 * (c) iBrand <https://www.ibrand.cc>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace iBrand\Sms\Jobs;
13
14
use Carbon\Carbon;
15
use DB;
16
use Illuminate\Bus\Queueable;
17
use Illuminate\Contracts\Queue\ShouldQueue;
18
use Illuminate\Foundation\Bus\Dispatchable;
19
use Illuminate\Queue\InteractsWithQueue;
20
use Illuminate\Queue\SerializesModels;
21
22
class DbLogger implements ShouldQueue
23
{
24
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
25
26
    private $code;
27
    private $result;
28
    private $flag;
29
30
    /**
31
     * Create a new job instance.
32
     */
33 26
    public function __construct($code, $result, $flag)
34
    {
35 26
        $this->code = $code;
36 26
        $this->result = $result;
37 26
        $this->flag = $flag;
38 26
    }
39
40
    /**
41
     * Execute the job.
42
     */
43 26
    public function handle()
44
    {
45 26
        if (!config('ibrand.sms.dblog')) {
46 22
            return;
47
        }
48 4
        DB::table('laravel_sms_log')->insert([
49 4
            'mobile' => $this->code->to,
50 4
            'data' => json_encode($this->code),
51 4
            'is_sent' => $this->flag,
52 4
            'result' => $this->result,
53 4
            'created_at' => Carbon::now(),
54 4
            'updated_at' => Carbon::now(),
55
        ]);
56 4
    }
57
}
58