AddWebhook   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 38
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 14 2
1
<?php
2
3
namespace Mpociot\CaptainHook\Commands;
4
5
use Exception;
6
use Illuminate\Console\Command;
7
use Mpociot\CaptainHook\Webhook;
8
9
class AddWebhook extends Command
10
{
11
    /**
12
     * The name and signature of the console command.
13
     *
14
     * @var string
15
     */
16
    protected $signature = 'hook:add
17
                            {url : The URL to use for the webhook}
18
                            {event : The namespaced class name of the event}';
19
20
    /**
21
     * The console command description.
22
     *
23
     * @var string
24
     */
25
    protected $description = 'Add a new webhook to the system.';
26
27
    /**
28
     * Execute the console command.
29
     *
30
     * @return mixed
31
     */
32
    public function handle()
33
    {
34
        $hook = new Webhook();
35
        $hook->url = $this->argument('url');
36
        $hook->event = $this->argument('event');
37
        try {
38
            $hook->save();
39
            $this->info('The webhook was saved successfully.');
40
            $this->info('Event: '.$hook->event);
41
            $this->info('URL: '.$hook->url);
42
        } catch (Exception $e) {
43
            $this->error("The webhook couldn't be added to the database ".$e->getMessage());
44
        }
45
    }
46
}
47