WebhooksController::execute()   A
last analyzed

Complexity

Conditions 3
Paths 6

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 0 Features 0
Metric Value
c 5
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 3
eloc 8
nc 6
nop 1
1
<?php namespace Bedard\Webhooks\Http;
2
3
use Request;
4
use Response;
5
use Exception;
6
use Bedard\Webhooks\Models\Hook;
7
use Illuminate\Routing\Controller;
8
9
class WebhooksController extends Controller
10
{
11
12
    /**
13
     * Execute a webhook
14
     *
15
     * @param  string   $token
16
     * @return Response
17
     */
18
    public function execute($token)
19
    {
20
        try {
21
            // If no webhook was found, return a 404
22
            if (!$hook = Hook::findByTokenAndMethod($token, Request::method())) {
23
                return Response::make(e(trans('bedard.webhooks::lang.responses.not_found')), 404);
24
            }
25
26
            // Otherwise queue the script for execution, and return a 200
27
            $hook->queueScript();
28
            return Response::make(e(trans('bedard.webhooks::lang.responses.success')), 200);
29
        } catch (Exception $e) {
30
            return Response::make(e(trans('bedard.webhooks::lang.responses.failed')), 500);
31
        }
32
    }
33
}
34