WebhookController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 12 2
A __construct() 0 3 1
1
<?php
2
3
namespace Signifly\Shopify\Http\Controllers;
4
5
use Exception;
6
use Illuminate\Http\JsonResponse;
7
use Illuminate\Http\Request;
8
use Illuminate\Http\Response;
9
use Illuminate\Routing\Controller;
10
use Illuminate\Support\Facades\Event;
11
use Illuminate\Support\Facades\Log;
12
use Signifly\Shopify\Http\Middleware\ValidateWebhook;
13
use Signifly\Shopify\Webhooks\Webhook;
14
15
class WebhookController extends Controller
16
{
17
    public function __construct()
18
    {
19
        $this->middleware(ValidateWebhook::class);
20
    }
21
22
    public function handle(Request $request)
23
    {
24
        try {
25
            $webhook = Webhook::fromRequest($request);
26
27
            Event::dispatch($webhook->eventName(), $webhook);
28
29
            return new JsonResponse();
30
        } catch (Exception $e) {
31
            Log::error($e->getMessage());
32
33
            return new Response('Error handling webhook', 500);
34
        }
35
    }
36
}
37