Completed
Push — master ( ce492c...ed54c9 )
by Freek
03:04 queued 11s
created

WebhookConfig   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 49
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Spatie\WebhookClient;
4
5
use Spatie\WebhookClient\Exceptions\InvalidConfig;
6
use Spatie\WebhookClient\SignatureValidator\SignatureValidator;
7
use Spatie\WebhookClient\WebhookProfile\WebhookProfile;
8
9
class WebhookConfig
10
{
11
    public string $name;
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_STRING, expecting T_FUNCTION or T_CONST
Loading history...
12
13
    public string $signingSecret;
14
15
    public string $signatureHeaderName;
16
17
    public SignatureValidator $signatureValidator;
18
19
    public WebhookProfile $webhookProfile;
20
21
    public string $webhookModel;
22
23
    public ProcessWebhookJob $processWebhookJob;
24
25
    public function __construct(array $properties)
26
    {
27
        $this->name = $properties['name'];
28
29
        $this->signingSecret = $properties['signing_secret'] ?? '';
30
31
        $this->signatureHeaderName = $properties['signature_header_name'] ?? '';
32
33
        if (! is_subclass_of($properties['signature_validator'], SignatureValidator::class)) {
34
            throw InvalidConfig::invalidSignatureValidator($properties['signature_validator']);
35
        }
36
        $this->signatureValidator = app($properties['signature_validator']);
37
38
        if (! is_subclass_of($properties['webhook_profile'], WebhookProfile::class)) {
39
            throw InvalidConfig::invalidWebhookProfile($properties['webhook_profile']);
40
        }
41
        $this->webhookProfile = app($properties['webhook_profile']);
42
43
        $this->webhookModel = $properties['webhook_model'];
44
45
        if (! is_subclass_of($properties['process_webhook_job'], ProcessWebhookJob::class)) {
46
            throw InvalidConfig::invalidProcessWebhookJob($properties['process_webhook_job']);
47
        }
48
        $this->processWebhookJob = app($properties['process_webhook_job']);
49
    }
50
}
51