Completed
Push — master ( 2fb369...5b2afe )
by Freek
17s queued 11s
created

WebhookCall::storeWebhook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Spatie\WebhookClient\Models;
4
5
use Exception;
6
use Illuminate\Http\Request;
7
use Illuminate\Database\Eloquent\Model;
8
use Spatie\WebhookClient\WebhookConfig;
9
10
class WebhookCall extends Model
11
{
12
    public $guarded = [];
13
14
    protected $casts = [
15
        'payload' => 'array',
16
        'exception' => 'array',
17
    ];
18
19
    public static function storeWebhook(WebhookConfig $config, Request $request): WebhookCall
20
    {
21
        return self::create([
22
            'name' => $config->name,
23
            'payload' => $request->input(),
24
        ]);
25
    }
26
27
    public function saveException(Exception $exception)
28
    {
29
        $this->exception = [
30
            'code' => $exception->getCode(),
31
            'message' => $exception->getMessage(),
32
            'trace' => $exception->getTraceAsString(),
33
        ];
34
35
        $this->save();
36
37
        return $this;
38
    }
39
40
    public function clearException()
41
    {
42
        $this->exception = null;
43
44
        $this->save();
45
46
        return $this;
47
    }
48
}
49