Completed
Pull Request — master (#4)
by Miguel
02:33
created

StripeWebhookCall::process()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Exception;
6
use Illuminate\Database\Eloquent\Model;
7
8
class StripeWebhookCall extends Model
9
{
10
    public $guarded = [];
11
12
    protected $casts = [
13
        'payload' => 'array',
14
        'exception' => 'array',
15
    ];
16
17
    public function process()
18
    {
19
        $jobClass = $this->determineJobClass($this->type);
20
21
        if (! class_exists($jobClass) {
0 ignored issues
show
Bug introduced by
Avoid IF statements that are always true or false
Loading history...
22
            return;
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_RETURN
Loading history...
23
        }
24
25
        dispatch(new $jobClass($this));
26
    }
27
28
    protected function determineJobClass(string $eventType): string
29
    {
30
        $jobConfigKey = str_replace('.', '_', $eventType);
31
32
        return config("stripe-webhooks.jobs.{$jobConfigKey}", '');
33
    }
34
35
    public function saveException(Exception $exception)
36
    {
37
        $this->exception = [
38
            'code' => $exception->getCode(),
39
            'message' => $exception->getMessage(),
40
            'exception' => $exception->getTraceAsString(),
41
        ];
42
43
        $this->save();
44
45
        return $this;
46
    }
47
}
48