Hooks   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 10
Bugs 1 Features 3
Metric Value
wmc 6
c 10
b 1
f 3
lcom 0
cbo 0
dl 0
loc 68
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A useAssets() 0 5 1
A listExtendQuery() 0 4 1
A onExecute() 0 6 1
A onEnable() 0 6 1
A onDisable() 0 6 1
1
<?php namespace Bedard\Webhooks\Controllers;
2
3
use Lang;
4
use Flash;
5
use Backend;
6
use Exception;
7
use BackendMenu;
8
use Backend\Classes\Controller;
9
use Bedard\Webhooks\Models\Hook;
10
use System\Classes\SettingsManager;
11
12
/**
13
 * Hooks Back-end Controller
14
 */
15
class Hooks extends Controller
16
{
17
    public $implement = [
18
        'Backend.Behaviors.FormController',
19
        'Backend.Behaviors.ListController',
20
        'Owl.Behaviors.ListDelete.Behavior',
21
        'Backend.Behaviors.RelationController',
22
    ];
23
24
    public $requiredPermissions = ['bedard.webhooks.manage_hooks'];
25
26
    public $bodyClass = 'compact-container';
27
    public $formConfig = 'config_form.yaml';
28
    public $listConfig = 'config_list.yaml';
29
    public $relationConfig = 'config_relation.yaml';
30
31
    public function __construct()
32
    {
33
        parent::__construct();
34
35
        $this->useAssets();
36
        BackendMenu::setContext('October.System', 'system', 'users');
37
        SettingsManager::setContext('Bedard.Webhooks', 'webhooks');
38
    }
39
40
    /**
41
     * Use the plugin assets
42
     *
43
     * @return void
44
     */
45
    protected function useAssets()
46
    {
47
        $this->addJs('/plugins/bedard/webhooks/assets/compiled/webhooks.min.js');
48
        $this->addCss('/plugins/bedard/webhooks/assets/compiled/webhooks.min.css');
49
    }
50
51
    /**
52
     * Join a subquery counting the logs.
53
     *
54
     * @param  \Illuminate\Database\Query\Builder $query
55
     * @return \Illuminate\Database\Query\Builder
56
     */
57
    public function listExtendQuery($query)
58
    {
59
        $query->joinLogsCount();
60
    }
61
62
    public function onExecute()
63
    {
64
        Hook::findOrFail(post('id'))->executeScript();
65
        Flash::success(Lang::get('bedard.webhooks::lang.hooks.execute_success'));
66
        return $this->listRefresh();
67
    }
68
69
    public function onEnable()
70
    {
71
        Hook::whereIn('id', post('checked'))->enable();
72
        Flash::success(Lang::get('bedard.webhooks::lang.hooks.status_enabled_msg'));
73
        return $this->listRefresh();
74
    }
75
76
    public function onDisable()
77
    {
78
        Hook::whereIn('id', post('checked'))->disable();
79
        Flash::success(Lang::get('bedard.webhooks::lang.hooks.status_disabled_msg'));
80
        return $this->listRefresh();
81
    }
82
}
83