ProcessWebhook::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace SirSova\Webhooks\Jobs;
5
6
use Illuminate\Bus\Queueable;
7
use Illuminate\Foundation\Bus\Dispatchable;
8
use Illuminate\Queue\InteractsWithQueue;
9
use SirSova\Webhooks\Contracts\Channel;
10
use SirSova\Webhooks\Message;
11
use SirSova\Webhooks\Webhook;
12
13
class ProcessWebhook
14
{
15
    use Dispatchable, InteractsWithQueue, Queueable;
16
17
    /**
18
     * @var Webhook
19
     */
20
    private $webhook;
21
22
    public function __construct(Webhook $message)
23
    {
24
        $this->webhook = $message;
25
    }
26
27
    /**
28
     * @param string      $type
29
     * @param             $context
30
     * @param string      $url
31
     * @param string|null $queue
32
     *
33
     * @return ProcessWebhook
34
     */
35
    public static function queued(string $type, $context, string $url, ?string $queue = null): self
36
    {
37
        return static::create($type, $context, $url)->onQueue($queue ?? config('webhooks.webhook-queue'));
38
    }
39
40
    /**
41
     * @param string $type
42
     * @param        $context
43
     * @param string $url
44
     *
45
     * @return ProcessWebhook
46
     */
47
    public static function create(string $type, $context, string $url): self
48
    {
49
        return new static(new Webhook(new Message($type, $context), $url));
50
    }
51
52
    /**
53
     * @param Channel $channel
54
     */
55
    public function handle(Channel $channel): void
56
    {
57
        $channel->send($this->webhook);
58
    }
59
}
60