GeneralController   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 5
dl 0
loc 58
ccs 0
cts 41
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A behaviors() 0 25 1
A verbs() 0 6 1
A actionSave() 0 12 1
1
<?php
2
3
/**
4
 * @copyright  Copyright (c) Flipbox Digital Limited
5
 * @license    https://flipboxfactory.com/software/hubspot/license
6
 * @link       https://www.flipboxfactory.com/software/hubspot/
7
 */
8
9
namespace flipbox\craft\hubspot\cp\controllers\settings;
10
11
use Craft;
12
use craft\helpers\ArrayHelper;
13
use flipbox\craft\hubspot\cp\actions\SaveSettings;
14
use flipbox\craft\hubspot\cp\controllers\AbstractController;
15
use flipbox\craft\hubspot\HubSpot;
16
17
/**
18
 * @author Flipbox Factory <[email protected]>
19
 * @since 1.0.0
20
 */
21
class GeneralController extends AbstractController
22
{
23
    /**
24
     * @return array
25
     */
26
    public function behaviors()
27
    {
28
        return ArrayHelper::merge(
29
            parent::behaviors(),
30
            [
31
                'error' => [
32
                    'default' => 'settings'
33
                ],
34
                'redirect' => [
35
                    'only' => ['save'],
36
                    'actions' => [
37
                        'save' => [200]
38
                    ]
39
                ],
40
                'flash' => [
41
                    'actions' => [
42
                        'save' => [
43
                            200 => HubSpot::t("Settings successfully saved."),
44
                            400 => HubSpot::t("Failed to save settings.")
45
                        ]
46
                    ]
47
                ]
48
            ]
49
        );
50
    }
51
52
    /**
53
     * @return array
54
     */
55
    protected function verbs(): array
56
    {
57
        return [
58
            'save' => ['post']
59
        ];
60
    }
61
62
    /**
63
     * @return mixed
64
     * @throws \yii\base\InvalidConfigException
65
     */
66
    public function actionSave()
67
    {
68
        /** @var SaveSettings $action */
69
        $action = Craft::createObject([
70
            'class' => SaveSettings::class
71
        ], [
72
            'save',
73
            $this
74
        ]);
75
76
        return $action->runWithParams([]);
77
    }
78
}
79