Completed
Push — master ( 16ed10...af0efe )
by Freek
01:45
created

ProcessStripeWebhookJob   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 2
dl 0
loc 30
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 20 5
A determineJobClass() 0 6 1
1
<?php
2
3
namespace Spatie\StripeWebhooks;
4
5
use Spatie\StripeWebhooks\Exceptions\WebhookFailed;
6
use Spatie\WebhookClient\ProcessWebhookJob;
7
8
class ProcessStripeWebhookJob extends ProcessWebhookJob
9
{
10
    public function handle()
11
    {
12
        if (!isset($this->webhookCall->payload['type']) || $this->webhookCall->payload['type'] === '') {
13
            throw WebhookFailed::missingType($this->webhookCall);
14
        }
15
16
        event("stripe-webhooks::{$this->webhookCall->payload['type']}", $this->webhookCall);
17
18
        $jobClass = $this->determineJobClass($this->webhookCall->payload['type']);
19
20
        if ($jobClass === '') {
21
            return;
22
        }
23
24
        if (! class_exists($jobClass)) {
25
            throw WebhookFailed::jobClassDoesNotExist($jobClass, $this->webhookCall);
26
        }
27
28
        dispatch(new $jobClass($this->webhookCall));
29
    }
30
31
    protected function determineJobClass(string $eventType): string
32
    {
33
        $jobConfigKey = str_replace('.', '_', $eventType);
34
35
        return config("stripe-webhooks.jobs.{$jobConfigKey}", '');
36
    }
37
}
38